element-----------打印的数据
想把每一条数据的specItems的image赋值给specItem,但是现在页面上的dom没有更新,需要再次点击,求详细解释,这里的$set应该怎么写
// 表格插入图片
createImgsObj() {
this.$forceUpdate();
let imgsObj = {}
let tableCategoryList = this.tableCategoryList
// 循环规格值的数组
for (let index = 0; index < tableCategoryList.length; index++) {
const element = tableCategoryList[index]
console.log(element,'element-----------');
if (element.specItems.length > 0) {
let specItems = element.specItems
console.log(specItems,'specitems===========')
for (let i = 0; i < specItems.length; i++) {
const tempArray = specItems[i]
console.log(tempArray,'jjj')
console.log(tempArray.specItem,'k==================v')
// imgsObj[tempArray.specItem] = tempArray.image;
// imgsObj[tempArray.specItem] = tempArray.image; 把tempArray里面的imgage给到this.imgsObj tempArray里面的specItem
this.$set(imgsObj,'specItem',tempArray.image)
// imgsObj[tempArray.specItem] = 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg'
你要说清楚,你使用的js库是什么?
不然,不好判断$.set里面做什么操作?
看到你上个问题,大佬说用$.set,不知道你具体的逻辑,我一般是用push,界面也会显示数据
首先页面没有更新是数据不是双向绑定的问题,可以使用$.set解决。
写法:this.$set(tempArray,'specItem',tempArray.image) 这样就是在tempArray对象上添加specItem属性,属性值为tempArray.image