我有一个项目,其中使用了许多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为空。
const options_select出现错误
TypeError:“ this。$ options_select未定义;无法访问其“ length”属性”
如果我对每个vue-select使用专用功能...正在工作,则每个vue-select都将填充来自axios的数据(使用load()方法)。
有什么想法吗?
答案 0 :(得分:0)
找到解决方案:
...
maybeLoad(name) {
const options_select = 'options_' + name;
return this[options_select].length <= 0 ? this.load(name) : null
},
...