如题所示,在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
// })
试试 $forceUpdate() ,
vue 判断数据是否更新这部分 有点不准。