
list就是你获取的数据数组
computed:{ sortlist(){ return this.sortlist.sort((a, b) => { return a['value'].localeCompare(b['value']) //value是list你需要索引的字段名称 }) } }
不要在计算属性内直接修改data里面的数据,eslint会报 no-side-effects-in-computed-properties 错误
如果非要改可以写在一个函数里,然后在计算属性里调用该函数。建议使用如下这种方式
computed: { //按A-Z排序 reorder() { return this.sortZZS() } }, methods: { sortZZS(){ return this.sortlist.sort((a, b) => { return a['value'].localeCompare(b['value']) //index是list你需要索引的字段名称 }) }, }
注意:索引的字段名称填错的话就会报错