Under certain conditions, move the position of the v-text-field text
P粉041856955
P粉041856955 2023-08-28 21:40:26
0
2
506
<p>I'm using Vue.js and Vuetify. Encountered an interesting scene. So I have three options (radio buttons)</p> <ul> <li>left</li> <li>中</li> <li>right</li> </ul> <p>I have a v-text-field with a specific text value and a read-only attribute. Now, when the option changes/selects, I want to change the position of that text within the v-text-field. </p> <p>For example, when option 1 (left), the text should be moved to the left within the v-text-field. When option 2 (middle) is used, the text should move to the middle. So on and so forth. </p> <p>Any suggestions on this. If there is a better way, please guide me. </p>
P粉041856955
P粉041856955

reply all(2)
P粉306523969

You can use class or style binding in Vue

data() {
  return {
    activeAlignment: 'center'
  }
}
<div :style="{text-align : activeAlignment} ></div>

Then bind activeAlignment to your radio button model

P粉466290133

You can create classes and bind them:

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data: () => ({
    text: 'some text',
    align: ''
  })
})
.left .v-text-field__slot textarea, .left .v-text-field__slot input {
  text-align: left;
}
.center .v-text-field__slot textarea, .center .v-text-field__slot input {
  text-align: center;
}
.right .v-text-field__slot textarea, .right .v-text-field__slot input {
  text-align: right;
}
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@6.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
</head>
<body>
<div id="app">
  <v-app>
    <v-main>
      <v-container>
        <v-btn-toggle
          v-model="align"
          tile
          color="deep-purple accent-3"
          group
        >
          <v-btn value="left">左对齐</v-btn>
          <v-btn value="center">居中对齐</v-btn>
          <v-btn value="right">右对齐</v-btn>
        </v-btn-toggle>
        <v-textarea
          :class="align"
          v-model="text"
          label="文本"
        ></v-textarea>
        <v-text-field
          v-model="text"
          label="文本"
          :class="align"
        ></v-text-field>
      </v-container>
    </v-main>
  </v-app>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.js"></script>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!