use ref to locate dom, because it is located in a DOM node with v-if and v-for, so it is called in updated. After printing it, it is found that it will be called seven times, which may be due to the update of updated. Currently, there is no method to control the execution only once. The code for help ~
is as follows:
/ / get the product code and merchant code
getGoods : function () {
for(let i=0;i<this.$refs.goods.length;iPP) {
app.goodsData = Object.assign({}, app.goodsData, {
sugGoodsCode: this.$refs.goods[i].dataset.procode,
shopCode: this.$refs.goods[i].dataset.vender //data-procodedata-vender
})
app.goodsList.push(app.goodsData);
}
}
call in updated:
updated: function () {
this.getGoods();
}
print in the background, there is no problem with the data, but there is a problem of repeated execution: