vue中陣列不具有響應式,需要使用vue.$set()
阿新 • • 發佈:2020-12-09
技術標籤:vue
1.在掉完介面後在陣列中的每一項新增三個屬性
orderStatus(id){
this.api.orderListStatus ({order_id:id}).then(res=>{
this.datalist = res.order_detail
this.goods_info = res.order_detail.goods_detail
res.order_detail.goods_detail.map(item=>{
item['comment']=''
item['imgList']=[]
item['remnant' ] =0
})
console.log(this.goods_info)
}).catch(err=>{
})
},
2.通過上傳輸入改變屬性的屬性值
若是直接改變remnant的值,頁面並沒有渲染,這裡就是需要用到$.set(),改變陣列的值,是不具有響應式的,或者也可以重新賦值,賦值到一個空陣列上
// 輸入框字數
descInput(e,index){
// this.remnant=12
this.goods_info.map((item,cindex)=>{
if(index==cindex) {
item.remnant=e.detail.value.length
this.$set(this.goods_info,index,item)
}
})