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>