学校后勤网站建设的作用,前端做网站要会什么,wordpress 256m内存,做的好的大学生旅行有哪些网站好在Vue官方文档中指出#xff0c;$forceUpdate具有强制刷新的作用。 那在vue框架中#xff0c;如果data中有一个变量:age#xff0c;修改他#xff0c;页面会自动更新。 但如果data中的变量为数组或对象#xff0c;我们直接去给某个对象或数组添加属性#xff0c;页面是识…在Vue官方文档中指出$forceUpdate具有强制刷新的作用。 那在vue框架中如果data中有一个变量:age修改他页面会自动更新。 但如果data中的变量为数组或对象我们直接去给某个对象或数组添加属性页面是识别不到的
templatep{{userInfo.name}}/pbutton clickupdateName修改userInfo/button
/templatescriptdata(){return{userInfo:{name:小明}}},methods:{updateName(){this.userInfo.name小红}}
/script在updateName函数中我们尝试给userInfo对象修改值发现页面其实并没有变化
那这时候有两种解决方法
方法一
methods:{updateName(){this.userInfo.name小红//在此时确实已经将userInfo对象修改完成console.log(this.userInfo.name);//输出结果: 小红this.$forceUpdate();//在这里强制刷新之后页面的结果变为小红}
}
方法二
methods:{updateName(){this.$set(userInfo,name,小红);}
}