1 Star 0 Fork 0

Hanley / study-front

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
27th.html 962 Bytes
一键复制 编辑 原始数据 按行查看 历史
hanley 提交于 2018-07-02 22:50 . fix 27th.html
<!DOCTYPE html>
<html>
<head>
<title>$set $delete</title>
<script src="vue.js"></script>
<script>
var vm = null;
window.onload=function(){
vm = new Vue({
el:'#my',// 2.0不允许挂载到html,body元素上
data:{
name:'moris',
age:22,
user:{
id:100,
name:'sonia',
msg:'12345'
},
},
methods:{
update(){
this.user.age="xxxx"
},
add() {
//this.user.name='ww';
//对象属性内部添加/删除 添加属性
//this.user.age = 22;//无效
this.$set(this.user,'age',22);
//vue.set(target,key,value)
},
del() {
//this.user.age = 22;//无效
this.$delete(this.user,'age');
}
},
});
}
</script>
</head>
<body>
<div id="my">
<h2>{{user.name}}</h2>
<h2>{{user.age}}</h2>
<button @click="add">add</button>
<button @click="update">update</button>
<button @click="del">del</button>
</div>
</body>
</html>
1
https://gitee.com/thanlin/study.git
git@gitee.com:thanlin/study.git
thanlin
study
study-front
master

搜索帮助