直接上代码

vm.$emit( eventName, […args] ) 触发当前实例上的事件 可选附加参数 传给监听器回调。

<style>
#app{ margin: 100px; }
#app>input, #app>button, ul li button{ border: none; outline: none; box-shadow: 0 1px 6px #dedede; background: #fff; }
#app>input:focus, #app>button:hover, ul li button:hover{ box-shadow: 0 2px 4px #ccc; }
#app>input{ padding: 6px 10px; width: 200px; }
#app>button{ padding: 6px 10px; height: 30px; cursor: pointer; }
ul{ padding: 0; }
ul li{ width: 280px; list-style: none; margin-top: 10px; }
ul li button{ float: right; width: 30px; cursor: pointer; }
</style>
<div id="app">
<input v-model="txt" type="text" @keyup.enter="handleSubmit">
<button @click="handleSubmit">submit</button>
<ul>
<todo-item
v-for="(item, index) in list"
:key="index"
:content="item"
:index="index"
@delete="handleDelete"
></todo-item>
</ul>
</div>
<script>
Vue.component('todo-item', {
props: ['content', 'index'],
template: '<li>{{index}}. {{content}} <button @click="handleClick">x</button></li>',
methods: {
handleClick () {
this.$emit('delete', this.index)
}
}
})
new Vue({
el: '#app',
data: {
txt: '',
list: []
},
methods: {
handleSubmit () {
if(!this.txt) return;
this.list.push(this.txt);
this.txt = '';
},
handleDelete (index) {
this.list.splice(index, 1)
}
}
})
</script>

最新文章

  1. 管道通信,王明学learn
  2. Android颜色资源文件
  3. Timer的用法
  4. centos 下Supervisor 守护进程基本配置
  5. Lintcode: Previous Permuation
  6. Sublime Text 2 常用快捷键
  7. scanf,sscanf利用format跳过干扰的空格
  8. UIButton的imageEdgeInsets 和 titleEdgeInsets
  9. MyBatis(3.2.3) - One-to-many mapping
  10. Access增删改查 (持续更新中)
  11. 修改 suse 上的postfix 的日志路径
  12. Java基础知识强化97:final、finally、finally区别
  13. MediaInfo源代码分析 1:整体结构
  14. 初学者的jquery登录注册和弹窗设计
  15. 终于会用c#中的delegate(委托)和event(事件)了
  16. JVM知识在离线数据中的运用
  17. 剑指Offer——好未来视频面知识点储备+面后总结
  18. [Swift]LeetCode996. 正方形数组的数目 | Number of Squareful Arrays
  19. 【js】js声明与数据类型
  20. RT-thread嵌入式操作系统相关的问题

热门文章

  1. Netty中CompositeByteBuf的理解以及读写操作
  2. 【Unity|C#】基础篇(12)——反射(Reflection)(核心类:Type、Assembly)
  3. MyBatis 中 Mapper 接口的使用原理
  4. asp.net web core 部署问题汇总
  5. openWRT和LuCI
  6. 常用sql 2018.08.31
  7. ALSA lib-io plugin
  8. 126. 单词接龙 II
  9. Jmeter-功能概要
  10. Devexpress 18.2.7 破解