020——VUE中变异方法push的留言版实例讲解

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>变异方法push的留言版实例讲解</title>
		<script src="vue.js"></script>
	</head>
	<body>
		<div id="lantian">
			<li v-for="v in comments">
				{{v.content}}
			</li>
			<textarea v-model="current_content" rows="10" cols="50"></textarea><br />
			<button v-on:click="push">提交</button>
		</div>
		<script>
			var app=new Vue({
			el:'#lantian',
			data:{
				current_content:'',
				comments:[
					{content:'小二'},
					{content:'小三'}
				]
			},
			methods:{
				push(){
					var content={content:this.current_content};
					this.comments.push(content);
					this.current_content='';
				}
			}
		});
		</script>
	</body>
</html>

  

原文地址:https://www.cnblogs.com/yiweiyihang/p/8080377.html