vue.js - 如何在 vuetify 复选框中设置不确定状态?
问题描述
我在 Vuetify 中有一个复选框,起初它有一个不确定的状态。将其更改为 true 或 false 后,我有一个按钮可以将其重置为默认值并再次显示不确定状态,但它不起作用。怎么了?indeterminate 的默认值为真,值为空。
<v-checkbox
:indeterminate="indeterminate"
v-model="value"
></v-checkbox>
按钮执行此操作:
<v-btn @click="setToDefault()"> set to default </v-btn>
方法:
setToDefault(){
this.value = null
this.indeterminate = true
}
解决方案
组件侦听更改并indeterminate
在值更改为时将其设置false
为状态true
。因此,要实现这一点,您需要在复选框的 v-model 值更改时将indeterminate
值设置为。false
你可以通过听来做到这一点value
<v-checkbox
:indeterminate="indeterminate"
v-model="value"
label="My Checkbox"
></v-checkbox>
<v-btn @click="setToDefault()"> set to default </v-btn>
export default {
data: {
value: null,
indeterminate: false
},
watch: {
value(){
this.indeterminate = false
}
},
methods: {
setToDefault(){
// Also, below line should be removed.
// this.value = false
this.indeterminate = true
}
}
}
推荐阅读
- python - 如何改善服务器的连接?
- numpy - 为我的 python/numpy 神经网络实现偏置节点的最佳方法是什么?
- visual-studio - VS 2019 中的 master.dacpac 来自哪里?
- ruby-on-rails - 使用 ActiveRecord::connection.exec_query 时如何获取 JOIN 数据?
- vue.js - Vue Auth - 没有“访问控制允许来源”,但他在那里
- linq - 使用 Linq C# 从数据库列中获取值
- jquery - 在 prestashop 注册表单中添加日期选择器(生日)
- c# - 如何仅使用更改的文件更新我的项目?
- c# - DefaultHttpRequest 未捕获 # 查询字符串
- python - 如何使用 Ansible 格式化 SQL 查询