日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

实现升序降序功能(Vue、CSS)

發布時間:2024/3/26 vue 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 实现升序降序功能(Vue、CSS) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、Vue實現排序功能組件:升序、降序

效果圖:

封裝組件:

<template><div class="sort-box" @click="changeSort"><div :style="{ cursor: isCursor }">{{ name }}</div><div class="sort-con"><div class="s-item" :class="{ active: currentDesc == item.name }" v-for="(item, index) in sortIconList" :key="index"><i :class="`iconfont ${item.icon}`"></i></div></div></div> </template><script> export default {name: 'BaseSort',props: {currentDesc: {type: String,required: true,default: '',},name: {type: String,default: '',},isCursor: {type: String,default: 'pointer',},},data() {return {isActive: 0,sortIconList: [{name: 'asc',icon: 'icon-shengxu',},{name: 'desc',icon: 'icon-jiangxu',},],}},methods: {changeSort(index) {this.$emit('changeSort', this.currentDesc)},},created() {},watch: {}, } </script><style lang="scss" scoped> .sort-box {display: flex;align-items: center; } .sort-con {.s-item {cursor: pointer;position: relative;i {font-size: 13px;}&.active {i {color: #67e5ff;}}}.s-item:first-child {height: 14px;} } </style>

在頁面上調用:

<template><base-sort :name="'次數'" :currentDesc="currentDesc" @changeSort="changeSort"></base-sort> </template> <script> export default {data() {return{currentDesc: 'desc',}},methods:{changeSort(val) {this.currentDesc = val === 'asc' ? 'desc' : 'asc'},} } </script>

二、CSS實現升序、降序圖標

效果圖:

代碼實現:

<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>Title</title><style type="text/css">.on {border-bottom: 2px solid #e61773;width: 150px;height: 40px;display: table-cell;position: relative;}.on a {display: block;overflow: hidden;width: 100%;height: 30px;line-height: 30px;text-align: center;color: #5e5e5e;}.angle_top {content: '';width: 0;height: 0;display: block;border-style: solid;border-width: 0 6px 6px;border-color: transparent transparent #5e5e5e;position: absolute;transform: rotate(180deg);bottom: 14px;right: 17px;}.angle_bottom {content: '';width: 0;height: 0;display: block;border-style: solid;border-width: 0 6px 6px;border-color: transparent transparent #5e5e5e;position: absolute;top: 10px;right: 17px;}</style> </head> <body><div class="on"><a href="javascript:void(0)" data-category="price" data-orderby="asc" class="js_category">價格<i class="angle_top"></i><i class="angle_bottom"></i></a> </div> </body> </html>

三、升序降序邏輯(JS的sort方法)

var arr = [1,55,33,44,11,99,10,44]; // 降序 console.info(arr.sort(function(a, b) {return b - a; })); // 升序 console.info(arr.sort(function(a, b) {return a - b; })); // 升序 arr2 = [{sort: 21},{sort: 12},{sort: 33},{sort: 14},{sort: 55}]; console.info(arr2.sort(function(a, b) {return a.sort - b.sort; }));

總結

以上是生活随笔為你收集整理的实现升序降序功能(Vue、CSS)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。