【发布时间】:2018-08-05 19:22:15
【问题描述】:
我创建了这样的选择框: JS:
Vue.component("v-select", VueSelect.VueSelect);
new Vue({
el: "#app",
data: {
options: [
{ countryCode: "AU", countryName: "Australia" },
{ countryCode: "CA", countryName: "Canada" },
{ countryCode: "CN", countryName: "China" },
{ countryCode: "DE", countryName: "Germany" },
{ countryCode: "JP", countryName: "Japan" },
{ countryCode: "MX", countryName: "Mexico" },
{ countryCode: "CH", countryName: "Switzerland" },
{ countryCode: "US", countryName: "United States" }
],
selectedCountry = null;
someAnotherModel = null; // model for parent select box. country select box is depends on it.
},
});
HTML:
<v-select label="countryName" :options="options" v-model="selectedCountry"></v-select>
在另一个选择框的某个观察者中,我这样做:
if (this.someAnotherModel == null) {
this.selectedCountry = null; // if parent has not selected value, I nee clear also country select box, but isn't work
}
你能帮我修复我的代码吗?我的目标是:
- 清除动态选择的值和空选择框,我设置为模型 null 但此更改未反映在选择框中的选择值上
- 我还有另一个问题,我在文档中寻找它 (http://sagalbot.github.io/vue-select/docs/),但我没有找到它。如果我单击选定的选项,它将被取消选择并且选择框将被清除。我想拒绝这种行为,并且如果选项数组不为空,还设置为自动选择某个选项。
感谢您的建议。
【问题讨论】:
-
1) 数据应该是一个返回对象的函数。 2) selectedCountry 和 someOtherModel 不在数据内。
-
@ThomasKleßen 我会修复它。在这里重写代码是我的错。
标签: javascript vue.js vuejs2 vue-select