• VUE:Select2


    <template>
        <div>
            <ul class="skill">
                <li v-for='item of list' v-on:click='selectLi(item)'>{{item}}</li>
            </ul>
        </div>
    </template>
    
    <script>
    export default {
        name:'myul',
        props: ['list'],
        methods: {
            selectLi: function(item) {
            //$emit触发当前实例上的自定义事件 receive
            this.$emit('receive', item);
            }
        }
    }
    </script>
    <style>
        ul, li {
            margin: 0;
            padding: 0;
            list-style: none;
        }
        .skill li {
            font-size: 18px;
            line-height: 2rem;
            height: 2rem;
            padding-left: 5px;
            cursor: pointer;
        }
        .skill li:hover {
            background-color: #008b45;
        }
    </style>
    
    <template>
        <div>
            <div id="selectWrap">
            <div class="searchBox">
                <input type="text" :value="selectVal" @click='ulShow = !ulShow'/>
                <a href="#" rel="external nofollow" class="search" v-text='btnName'></a>
            </div>
            <div>
                <myul v-show='ulShow' v-bind:list='list' v-on:receive='changeVal'></myul>
            </div>
        </div>
    </template>
    
    <script>
    import Vue from 'vue'
    import myul from './myul'
    Vue.component("myul", myul)
    export default {
        name:'myselect',
        data() {
            return {
            ulShow: false, //默认ul不显示,单击input改变ul的显示状态
            selectVal: '' //选项值,input的值与选项值动态绑定
            }
        },
        props: ['btnName', 'list'],
        methods: {
            changeVal(value) {
                this.selectVal = value
            }
        }
    }
    </script>
    <style>
        #selectWrap {
             250px;
            padding: 2rem;
            background: #4682b4;
        }
        .searchBox input, .searchBox a {
            line-height: 1.5rem;
            height: 1.5rem;
            margin-bottom: 1rem;
            padding: 0 5px;
            vertical-align: middle;
            border: 1px solid #aaa;
            border-radius: 5px;
            outline: none;
        }
        .searchBox a {
            display: inline-block;
            text-decoration: none;
            background-color: #b1d85c;
        }
    </style>
    

      

    // The Vue build version to load with the `import` command
    // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
    import Vue from 'vue'
    import myselect from './myselect'
    
    Vue.config.productionTip = false
    
    /* eslint-disable no-new */
    new Vue({
      el: '#app',
      data: {
        data1: ['CSS', 'HTML', 'JavaScript']
      },
      components: {myselect},
      template: "<myselect btn-name='search' v-bind:list='data1' style='float: left;margin-right: 2rem;'></myselect>"
      
    })
    

      

  • 相关阅读:
    2018 ACM-ICPC 中国大学生程序设计竞赛暨丝绸之路程序设计竞赛
    牛客小白月赛2
    求n个数中前k个数,按之前的顺序输出(HK IPM)
    js_复选框单选与复选
    js_判断字符串中出现最多的字符的和次数
    js_倒计时
    海通证券面试
    上海利莫面试
    中焯信息面试
    富途面试
  • 原文地址:https://www.cnblogs.com/coshaho/p/12019508.html
Copyright © 2020-2023  润新知