Heim > Fragen und Antworten > Hauptteil
P粉3065239692023-08-29 14:57:47
你可以使用Vue中的class或style绑定
data() { return { activeAlignment: 'center' } }
<div :style="{text-align : activeAlignment} ></div>
然后将activeAlignment
绑定到你的单选按钮模型上
P粉4662901332023-08-29 12:21:57
您可以创建类并将它们绑定:
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>