vue笔记之v-model

<!-- 按回车键添加内容 -->
<input v-model="todoText" v-on:keyup.enter="addText">
<ul>
	<li v-for="item in items">
		{{item.text}}
	</li>
</ul>
<script>
export default {
  name: 'App',
  data: function () {
    return {
	    items: [],
	    todoText:''
   }
    
  },
  methods: {
    addText: function () {
	 this.items.push({
		text: this.todoText
	});
	this.todoText = "";    
    }
  }
}
</script>

猜你喜欢

转载自blog.csdn.net/qq_36781179/article/details/82745945