作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试禁用 的特定元素a-select .
为此,我有一个函数“check_function
”,当我想禁用一个元素时,我将返回字符串“disabled
”。
我有
<a-select @change="onTestChanged" :value="currentTestId" >
<a-select-option
v-for="test in tests" v-bind:key="test.id"
:value="test.id"
:disabled="check_function(test.id) == 'disabled'"
>
{{ test.testName }}
</a-select-option>
</a-select>
我想禁用我的
的一个元素a-select 当函数“
check_function
”返回“
disabled
”时。
async check_function(id) {
await this.$store.dispatch("fetch_test", id)
var save = this.$store.getters.get_test()
if (save.length == 0) {
console.log("disabled")
return "disabled"
}
},
基本上,当我查看
时控制台日志 ,它正在工作的条件。当我想禁用一个元素时,它会打印“
disabled
”。
check_function(id) {
return "disabled"
},
我选择的所有元素都被禁用。
最佳答案
不是答案,而是一些调试技巧
检查保存是否为空。
这将有助于确保至少您不会错过 if 检查,因为您的“保存”变量未定义或为空。
async check_function(id) {
await this.$store.dispatch("fetch_test", id)
var save = this.$store.getters.get_test()
if (!save || save.length == 0) {
console.log("disabled")
return "disabled"
}
},
在进入您的 if 检查之前检查它是否返回 null。
async check_function(id) {
await this.$store.dispatch("fetch_test", id)
return "disabled"
}
关于javascript - 如何使用 Ant Design Vue 在 Select 中禁用特定元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67906929/
我是一名优秀的程序员,十分优秀!