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>

 

Logo

前往低代码交流专区

更多推荐