我有一个项目,在这个项目中我使用了许多vue-select组件。
我的组件:
...
<v-select ref="select_1" :options="options_1" @search:focus="maybeLoad('1')">
</v-select>
<v-select ref="select_3" :options="options_2" @search:focus="maybeLoad('2')">
</v-select>
<v-select ref="select_3" :options="options_3" @search:focus="maybeLoad('3')">
</v-select>
...
我的方法:
...
maybeLoad(name) {
// Vue.prototype.$options_select = 'options_' + name;
// const options_select = 'options_' + name;
return this.$options_select.length <= 0 ? this.load(name) : null
},
...
我尝试使用Vue.prototype.$options_select
或const options_select
,但没有工作。
Vue.prototype错误:
vue-select为空。
常量选项出错_选择
TypeError:"this.$options_select未定义;无法访问其"length"属性">
如果我对每个vue选择都使用专用函数。。。正在工作,每个vue-select都填充了axios的数据(使用load((方法(。
有什么想法吗?
找到解决方案:
...
maybeLoad(name) {
const options_select = 'options_' + name;
return this[options_select].length <= 0 ? this.load(name) : null
},
...