vue 删除对象的元素 delete
data中定义一个formdata: {seen: true,from:{id:'',name:'',age:'',}}现在不需要age元素删除 delete this.from.age;场景form表单提交的时候新增的数据和编辑页面公用一个页面 ,在添加的时候不需要id而就可以delete删除id<!DOCTYPE html><html><head><m
·
data中定义一个form
data: {
seen: true,
from:{
id:'',
name:'',
age:'',
}
}
现在不需要age元素
删除 delete this.from.age;
场景form表单提交的时候新增的数据和编辑页面公用一个页面 ,在添加的时候不需要id而就可以delete删除id
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 </title>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<div id="app">
<script>
new Vue({
el: '#app',
data: {
seen: true,
from:{
id:'',
name:'',
age:'',
}
},
mounted() {
//this.initData();
this.from.id=1;
this.from.name='xc';
this.from.age=18;
this.from.content='xcvzxcvzxcv'; //直接添加元素
delete this.from.age;//删除age元素
console.log(this.from)
},
})
</script>
</body>
</html>
更多推荐
已为社区贡献7条内容
所有评论(0)