Vue升序降序(前端价格排序)
生活随笔
收集整理的這篇文章主要介紹了
Vue升序降序(前端价格排序)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
定義兩個按鈕
<div id="showGoods"><button @click="upchange">升序</button><button @click="downchange">降序</button></div> <div id="showGoods"><button @click="upchange">升序</button><button @click="downchange">降序</button><div> <!-- 商品組件--><new-ul :item="listinfo"></new-ul></div></div>vue
let vm = new Vue({ el: "#showGoods", data: {listinfo: null; //獲取到后臺提供的值},methods: {upchange() {//寫法一this.listinfo.sort((a,b)=>{//排序基于的數(shù)據(jù)return a.price - b.price;})},downchange() {//寫法二function sortData(a, b) {return b.price - a.price;} this.listinfo.sort(sortData);}} })?
總結(jié)
以上是生活随笔為你收集整理的Vue升序降序(前端价格排序)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 医院常见系统名称缩写
- 下一篇: 中国联通委任陈忠岳为总裁!