Sort an array in Vue.js

前端 未结 5 806
时光取名叫无心
时光取名叫无心 2020-12-13 00:02

How can I sort an array by name or sex before displaying it in a v-for loop? https://jsfiddle.net/rg50h7hx/

5条回答
  •  青春惊慌失措
    2020-12-13 00:47

    This works really cool:

    sortFunc: function (){
      return this.arrays.slice().sort(function(a, b){
        return (a.name > b.name) ? 1 : -1;
      });
    }
    

    call the function from HTML:

    • {{ array.name }}

提交回复
热议问题