【发布时间】:2021-09-10 09:12:21
【问题描述】:
我是 VueJs 的初学者,所以我遇到了这个问题
这是我的代码
<md-select placeholder="Seleccione Lote" v-model="selectedLote" name="lotes" id="lotes">
<md-option v-for="lote of lotes" value="lote.value">{{lote.text}}</md-option>
</md-select>
然后我有我的数组
data: () => ({
lotes: [],
selectedLote : null
})
然后我使用 this 填充这个数组(this.products 是一个从 api 请求填充的数组)
mounted(){
this.fillLotesArray();
},
methods:{
fillLotesArray(){
for(let product of this.products){
if(this.lotes.findIndex(lote => lote.value === product._source.Lote) === -1){
this.lotes.push({value:product._source.Lote, text:product._source.Lote});
}
}
}
}
使用 console.logs 我可以看到数组已正确填充,但选项没有
【问题讨论】:
-
你可以添加一个 v-if="lotes" 或者你可以让 lotes 成为一个计算属性。
-
this.products是在页面挂载之前还是之后从api请求中填充的?
标签: javascript vue.js materialize