拉丁的傳說
2018-10-04 10:11:05
我想實(shí)現(xiàn)一個(gè)像手機(jī)聯(lián)系人的一個(gè)的列表。并且通過首字母來分組。 請(qǐng)問如何用vue 里面的v-for 來渲染?HTML模板<li v-for="(item,index) in carbrands"> <h2 class="list-title" v-show="" >{{item.LETTER}} {{index}}</h2> <ul class="list-content"> <li class="list-car-item" @click="typeShow"><img :src="item.IMAGE" alt=""><span>{{item.NAME}}</span></li> </ul></li>數(shù)據(jù)通過data里的LETTER 想實(shí)現(xiàn)的效果我是菜鳥 ,請(qǐng)指教。
1 回答

揚(yáng)帆大魚
TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超9個(gè)贊
Vue 1.0 直接使用OrderBy進(jìn)行首字母排序
< v-for="(item,index) in carbrands | orderBy 'LETTER'">
// 數(shù)組第一個(gè)顯示LETTER以及現(xiàn)在的數(shù)組元素中的Letter!= 上一個(gè)數(shù)組元素中的Letter時(shí)顯示Letter。
v-show="index === 0 || item.LETTER !== carbrands[index-1].LETTER"
Vue 2.0 使用計(jì)算屬性
< v-for="(item,index) in carbrands">
v-show="index === 0 || item.LETTER !== carbrands[index-1].LETTER"
computed: {
carbrands: function () {
return _.orderBy(this.carbrands, 'LETTER');
}
}
溫馨建議:提問的時(shí)候直接貼代碼出來方便別人復(fù)制粘貼修改,你貼圖片很不方便
添加回答
舉報(bào)
0/150
提交
取消