sort.vue 1.82 KB
<template>
    <ul class="sort-navs clearfix">
        <template v-for="item in config">
            <simple v-if="(item.type || 'simple') === 'simple'" :txt="item.txt" :val="item.val">
            </simple>
            <updown v-if="item.type === 'updown'" :txt="item.txt" :vals="item.val">
            </updown>
        </template>
    </ul>
</template>
<script>
const $ = require('yoho-jquery');
const bus = require('common/vue-bus');
const simple = require('./sort/simple.vue');
const updown = require('./sort/updown.vue');

module.exports = {
    props: {
        /**
         * sort 配置
         * @type {Array}  [{type, txt, val}]
         *  type: 类型   simple, updown
         *  txt: 文字,
         *  val: 值
         */
        config: Array,

        // 初始值 可以进行双向绑定
        val: String
    },
    components: {
        simple,
        updown
    },
    methods: {},
    watch: {
        val: function(newVal, oldVal) {
            bus.$emit('sort.change', {
                val: newVal,
                ref: this._uid
            });
        }
    }
};
</script>
<style>
@import "../../../scss/common/color";

.sort-navs {
    list-style: none;
    margin: 0;
    padding: 25px 0;
    color: $grey;
}

.sort-item {
    position: relative;
    display: block;
    width: 25%;
    float: left;
    text-align: center;
    &:after {
        content: "|";
        position: absolute;
        right: 0;
        color: $grey;
        font-size: 28px;
    }
    &:last-of-type:after {
        display: none;
    }
    .sort-name {
        font-size: 28px;
    }
    .sort-icon {
        position: relative;
        margin-left: 10px;
        .icon-sort-asc,
        .icon-sort-desc {
            position: absolute;
            left: 0;
            top: 0;
        }
    }
    &.active {
        color: $black;
    }
}
</style>