vue 根據指定欄位排序使用computed 方法
<div id="app"> <ul> <li v-for="(stu,index) in students1">{{stu}}</li> </ul> </div> <script type="text/javascript"> new Vue({ el:"#app", data:{ students:[ {name:"小a",age:20}, {name:"小b",age:21}, {name:"小c",age:18}, {name:"小d",age:19}, {name:"小f",age:18} ] }, computed:{ students1:function(){ return sortKey(this.students,'age') } } }) function sortKey(array,key){ return array.sort(function(a,b){ var x = a[key]; var y = b[key]; return ((x<y)?-1:(x>y)?1:0) }) } </script>