猿问

vue v-for循环新增对象视图不更新

如题所示,在vm中利用对象数据和v-for进行列表渲染,但是在对象数据中新增一条键值为对象的数据之后,发现视图并未更新。查看官方文档也不知道该怎么写,求大牛赐教。代码如下:


    let shellObj = {};

    shellObj.name = name;

    shellObj.runCode = runCode;

    shellObj.storePath = storePath;

    if (file) {

      shellObj.filePath = file.path;

      fs.createReadStream(file.path)

         .pipe(fs.createWriteStream(userPath + '/Shell/' + file.name))

              .on('close', function () {

                  shellJson[name] = shellObj;

                  that.hideBlack();

              });

    } else {

      shellObj.filePath = '';

      shellJson[name] = shellObj;

      that.hideBlack();

    }

  shellJsonCopy[name] = shellObj;

  // shellJson = Object.assign(shellJson,shellJsonCopy);

  body.$set(body.$data.shellData,name, shellObj);

  // shellJson = Object.assign({}, shellJson, {

  //     [name]: shellObj

  // })


GCT1015
浏览 950回答 1
1回答

慕莱坞森

试试 $forceUpdate() ,vue 判断数据是否更新这部分 有点不准。
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答