vue的实现自定义下拉select样式

  <template>
                <div class="select">
                    <div class="select-head c-row a-c j-b"  v-on:click="changeSiteTitle()">
                        <span class="select-head-cont" >{{condition}}</span>                   
                        <img class="selct-img" src="./img/select.png">
                    </div>
                    <ul class="option"  v-show="option">
                        <li class="option-item  c-row a-c" v-for="item in siteList" v-on:click="changeSite(item)">            
                        {{item.siteName}}</li>
                    </ul>
                </div>
        </template>

//css样式
.select {
    margin-top: .32rem;
    padding: 0 .25rem;
    width: 6.9rem;
    height: .8rem;
    color: #666666;
    font-size: .3rem;
    background-color: #f2f2f2;
}

.selct-img {
    width: .21rem;
    height: .11rem;
}

.select {
    position: relative;
    font-size: .30rem;
}

.select-head {
    /* overflow: hidden; */
    height: .8rem;
    color: #202020;
    box-sizing: border-box;
    line-height: .8rem;
}

.select-head .select-head-cont {
    float: left;
    padding-right: 10px;
}

.select:hover .option {
    display: block;
}

.option {
    position: absolute;
    left: 0;
    color: #63666E;
    background: #FFFFFF;
    line-height: 25px;
    display: none;
    z-index: 20000;
    box-shadow: 0px 2px 15px 0px rgba(0, 0, 0, 0.09);
    text-align: left;
}

.option-item {
    border-bottom: .5px solid rgba(197, 197, 197, 0.27);
    width: 6.9rem;
    padding: 0 .25rem;
    height: .8rem;
}

.option-item:last-child {
    border: none;
}
//js
var app = new Vue({
    el: "#app",
    data: {
        option: false,
        condition: "按月筛选",
        siteList: [{ 

                siteName:   "按月筛选"
            }, { 

                siteName:   "按季筛选"
            },
            { 

                siteName:   "按年筛选"
            }
        ],


    },
    methods: {
        changeSite(e) {
            console.log(e.siteName)

            this.condition = e.siteName
            this.option = false;
        },
        changeSiteTitle() {
            this.option = !this.option

        }


    }
})

你可能感兴趣的:(html)