最近在做vue的练习,发现有些js中的基础知识掌握的不牢,记录一下:

1、onchange事件:是在域的内容改变时发生,单选框与复选框改变后触发的事件。

2、push方法:向数组的末尾添加一个或多个元素,并返回新的长度 array.push(item1,item2,...,itemx)

3、splice方法:用于插入、删除或替换数组元素 array.splice(index,howmany,item1,...itemx)

4、forEach()方法:用于调用数组的每一个元素,并将元素传递给回调函数。array.forEach(function(currentValue,index,arr),thisValue)

例子:计算未采购的数量

<input type="text" class="form-control" v-model="text">
<button class="btn btn-default" type="button" @click="addClick(text)">添加</button>
<small>未采购数<button type="button">{{num}}</button></small>
          <tr v-for="(item,index) in listArr">
      <td>{{item.sName}}</td>
<td><input type="checkbox" v-model="item.flag" @change="action"></td>
<td>{{item.flag}}</td>
<td><button type="button" class="btn btn-default" @click='del(i)'>删除</button></td>
</tr>

 

js部分:
new Vue({
el:'myList',
data:{
num:0,
listArr:[{sName:'衣服',flag:false},{sName:'鞋子',flag:false},{sName:'裙子',flag:false}]
},
methods:{
addClick:function(text){
if(text=='') return;//输入为空就返回
this.listArr.push({sName:text,flag:true})//添加
this.text=''//添加后输入框清空
this.action()
},
action:function(){
var _this=this;
_this.num=0;
this.listArr.forEach(function(item,index)){
if(!item.flag){ _this.num++ }
})
},
del:function(i){
this.listArr.splice(i,1)
}
} })

 

最新文章

  1. Linux CentOS 配置JDK环境
  2. Winform无边框窗体的移动和阴影
  3. JDBC编程
  4. VI命令----用于检索
  5. php URL判断
  6. svn代码回滚命令
  7. Java中的线程
  8. JS模态窗口返回值兼容问题解决方案
  9. android游戏动画特效的一些处理
  10. Memcache+Cookie解决分布式系统共享登录状态------------------------------Why Memcached?
  11. Candy Sharing Game(hdoj1034)
  12. dev XtraMessageBox按钮显示中文
  13. opencv探索之路(一):win10 X64+VS2015+opencv3.10安装教程
  14. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6155 Subsequence Count 矩阵快速幂
  15. C++继承分析
  16. Linux kernel的中断子系统之(八):softirq
  17. Elasticsearch与Hadoop集成大数据处理介绍
  18. No.0
  19. go 变量声明
  20. 啰哩吧嗦式讲解在windows 家庭版安装docker

热门文章

  1. css css3新特性
  2. ubuntu - 14.04,安装CDT(Eclipse开发C++和C的插件)
  3. C#之重载
  4. ASP.NET-GridView之表头设计
  5. 16.Shortest Unsorted Continuous Subarray(最短未排序子数组)
  6. 2.mybatis 的列名与数据库字段不对应
  7. Codeforces - 625B 贪心
  8. php设计模式总结2
  9. jgroups-raft
  10. UML箭头