vue开发源码:https://vuejs.org/js/vue.js

todolist代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vue入门</title>
<script src="vue.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="app">
<input v-model="inputValue" type="text" name="">
<button @click="submit">提交</button> <ul>
<todo-item
v-for="(item, index) in list"
:key="index"
:content="item"
:index="index"
@delete="handleDelete"
@update="handleUpdate"
>
</todo-item>
</ul>
<input v-model="updateValue" type="text" name="">
<button @click="update">确定</button>
</div>
</body>
<script type="text/javascript"> Vue.component("todo-item", {
props:["content", "index"],
template:'<li>{{content}} <button @click="handleClick">remove</button><button @click="handleUp">update</button></li>',
methods:{
handleClick:function() {
this.$emit('delete', this.index)
},
handleUp:function() {
this.$emit('update', this.index)
}
}
}) new Vue({
el:"#app",
data: {
inputValue : '',
updateValue : '',
in:'',
list:[]
},
methods: {
submit:function() {
if(this.inputValue.trim() !== "") {
this.list.push(this.inputValue);
}
this.inputValue = ''
},
handleDelete: function(index) {
this.list.splice(index, 1);
},
handleUpdate: function(index) {
this.updateValue = this.list[index]
this.in = index;
},
update: function() {
console.log(this.in)
this.list.splice(this.in, 1, this.updateValue);
this.updateValue = ''
}
}
})
</script>
</html>

  重点:子组件与父组件的值传递

最新文章

  1. spring boot整合shiro出现UnavailableSecurityManagerException
  2. 关于在程序中 文件新生成 在用os.system()程序对新生成的文件处理 举个栗子 如下:
  3. World of Warcraft
  4. In Action(SPFA+01背包)
  5. Unix Linux 编程书籍
  6. 制作越狱版本的ipa文件
  7. 【转】 iOS使用AVFoundation实现二维码扫描
  8. C#中关于DBNULL的处理方法
  9. UpdateModel方法
  10. 2013集训.DAY21.A
  11. cadence pcb 设计学习记录提纲
  12. 【LeetCode】258. Add Digits
  13. 微信开发系列——微信订阅号前端开发利器:WeUI
  14. Linxu命令与文件的搜索 - which, whereis, locate, find
  15. 20165234 《Java程序设计》第五周学习总结
  16. Python爬虫:如何爬取分页数据?
  17. shell监控脚本实例—监控mysql主从复制
  18. 【BZOJ】1679: [Usaco2005 Jan]Moo Volume 牛的呼声(数学)
  19. http状态码+http请求方式
  20. webapi2返回 已拒绝为此请求授权。

热门文章

  1. [daily][centos][sudo] sudo 报错
  2. [daily][centos] redhat增加扩展仓库
  3. day2_抓包-抓包工具Charles
  4. Java之旅_高级教程_实例_数组
  5. Java如何对List集合的操作方法(一)
  6. Ubuntu14.04 LTS 安装Chrome浏览器(转)
  7. Swift中"#"的用法
  8. ActiveMQ整合spring、同步索引库
  9. 汇编-5.0-[BX]和loop指令
  10. SQL Server Management Studio最新版下载地址