gpt4 book ai didi

vue.js - 将 v-switch 设置为打开,值为 : 'false' (invert value with v-model)

转载 作者:行者123 更新时间:2023-12-05 00:42:04 24 4
gpt4 key购买 nike

我有一个 v-switch,我希望它是“on/true”,这样开关就在右边,但 v-model 的值仍然是“false” ,然后当开关为“off/false”时,将 v-model 值设为“true”,本质上是反转值。

我正在努力寻找这个选项或如何做到这一点。我正在使用 Vuetify 1.5.15:

<v-switch color="success" prepend-icon="notifications_off" v-model="url.muteNotifications" @click.capture.prevent.stop="togglePolling(url, urlNo)"></v-switch>

最佳答案

它不是值(value) - 它的 input-value

new Vue({
el: '#app',
data(){
return {
t:false
}
},
methods: {
change(){
console.log("change");
this.t=!this.t;
}
},
vuetify: new Vuetify(),
})
<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@3.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">
<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>

<div id="app">
<v-app>
<v-content>
<v-switch :input-value="!t" @change="change">Hello world</v-switch>
</v-content>
</v-app>
</div>

但您也可以将 false 定义为 truish

new Vue({
el: '#app',
data(){
return {
t:false
}
},
vuetify: new Vuetify(),
})
<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@3.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">
<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>

<div id="app">
<v-app>
<v-content>
<v-switch v-model="t" :false-value="true" :true-value="false">Hello world</v-switch>
</v-content>
</v-app>
</div>

但这会中断 colors - imo a bug

关于vue.js - 将 v-switch 设置为打开,值为 : 'false' (invert value with v-model),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57571400/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com