vue.js 数组更新
改变原始数组
push()
pop()
shift()
unshift()
splice()
sort()
reverse()
不改变原数组
filter()
contat()
slice()
实例:
computed:{
filterBooks(){
return this.books.filter(function(book){
return book.name.match(/javascript/)
})
},
sortBooks(){
return this.lists.sort(function (a,b) {
return a.name.length<b.name.length
})
}
}mounted(){
this.books.push({ //push数组方法,视图直接改变
name:"《css3实战》",
author:"huiyh"
});
this.books=this.books.concat([{ //concat数组方法,需更新原数组
name:"《html5实战》",
author:"lala"
}])
}声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: 关于使用vue.js提交数组时出现数组下标的问题
- 下一篇: Vue.js
