vue.js - V-chip-group 值未定义
问题描述
我经常使用 Vuetify v-chip-group 遇到这个问题。
我正在使用 v-chip-group v-model,这是选定的芯片索引。
<v-chip-group
v-model="selectedItem"
>
我将值设置为 -1,所以默认情况下没有选择 v-chip
data() {
return {
selectedItem: -1,
}
}
The problem I encounter is when a v-chip is selected, it changes the value from its default, but when this v-chip item is deleted from the list, the selectedItem value becomes undefined.
在没有任何选定筹码的情况下,有没有办法将值恢复为 -1 ?
解决方案
您可以查看该值然后将其重置,但我想知道您为什么想要这种行为?是不是因为您需要评估该值是否为 -1 以便您可以做其他事情?我之所以问是因为我觉得组件在取消选择时将其值设置为“未定义”是有意义的。
data() {
return {
selectedItem: -1
};
},
watch: {
selectedItem(v) {
console.log(v);
if (!v) {
this.selectedItem = -1;
}
}
}
推荐阅读
- integromat - Integromat Watch Google Contacts - 删除操作怎么办?
- android - 如何访问文件夹特定的应用程序android studio
- python - 无法 pip 安装 dlib
- python - Python/SQLAlchemy 中的部分 UUID 匹配
- flutter - 如何更改它以使更改立即生效?
- sql - 将 Redshift 中的两列相加
- powershell - Remove the display:none attribute so that the item will be visible
- python - 如果单元格有 2 个单词,则仅提取第一个单词,如果单元格有 3 个单词,则提取 2 个第一个单词 - PANDAS/REGEX
- python - 使用 opencv 和 gstreamer 在网络服务器上发送我的网络摄像头视频时丢失关键帧
- flutter - Flutter Resize ImagePicker Image 在上传到firebase之前