Home >Web Front-end >JS Tutorial >vue.js array update example sharing

vue.js array update example sharing

小云云
小云云Original
2018-03-19 16:02:131521browse

This article mainly shares vue.js array update examples with you, hoping to help everyone.

Change the original array

push()

pop()

shift()

unshift()

splice()

sort()

reverse()

Does not change the original array

filter()

contat()

slice()

Example:

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:&#39;《css3实战》&#39;,
            author:&#39;huiyh&#39;
        });
        this.books=this.books.concat([{  //concat数组方法,需更新原数组
            name:&#39;《html5实战》&#39;,
            author:&#39;lala&#39;
        }])
}

The above is the detailed content of vue.js array update example sharing. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn