
由于数据结构的原因,v-for 的是对象属性,每个属性又是一个对象,现在希望让列表按 order 这个属性进行排序,请问能做到吗?
const objects = { prop1: { text: 'a', order: 3 }, prop2: { text: 'c', order: 1 }, prop3: { text: 'b', order: 2 }, } <template v-for="(value, key) in objects"> <div>{{ value.text }}</div> </template> 希望的 output
c b a 1 zzetao 2017-05-22 22:48:33 +08:00 |
2 Biwood 2017-05-22 22:52:43 +08:00 手动给数据排序也不是什么麻烦事,新建一个数组,用 order 作为索引并赋值对应的值 |
3 Sparetire 2017-05-23 08:23:37 +08:00 via Android 用计算属性吧 |
4 470326964 2017-06-02 13:52:48 +08:00 计算属性返回值,然后拿返回值去遍历。 |