• Vue练习三十六:05_01_模拟select控件


    Demo 在线地址:
    https://sx00xs.github.io/test/36/index.html
    ---------------------------------------------------------------
    ide: vscode
    文件格式:.vue
    解析:(待补)

    <template>
        <div class="search">
            <div class="box" v-clickoutside="handleClose">
                <form>
                    <span class="select" @click.prevent="handleClick">{{message}}</span>
                    <a href="#">搜索</a>
                </form>
            </div>
            <ul class="sub" v-show="show">
                <li v-for="item in lists" :key="item.mes" :class="{hover:item.isActive}"
                @mouseover="handleOver(item)"
                @mouseout="handleOut(item)"
                @click="handleSubClick(item)"
                >
                    {{item.mes}}
                </li>
            </ul>
        </div>
    </template>
    <script>
    export default {
        data(){
            return{
                message:'请选择游戏名称',
                show:false,
                lists:[
                    {
                        mes:'地下城与勇士',
                        isActive:false
                    },
                    {
                        mes:'魔兽世界(国服)',
                        isActive:false
                    },
                    {
                        mes:'魔兽世界(台服)',
                        isActive:false
                    },
                    {
                        mes:'热血江湖',
                        isActive:false
                    },
                    {
                        mes:'神鬼传奇',
                        isActive:false
                    },
                    {
                        mes:'大话西游II',
                        isActive:false
                    },
                    {
                        mes:'QQ幻想世界',
                        isActive:false
                    },
                ]
            }
        },
        methods:{
            handleClose(){
                this.show=false
            },
            handleClick(){
                this.show=this.show===false ? true : false
            },
            handleOver(item){
                item.isActive=true
            },
            handleOut(item){
                item.isActive=false
            },
            handleSubClick(item){
                this.message=item.mes;
                this.show=false
            },
            
        },
        directives:{
            clickoutside:{
                bind(el,binding,vnode){
                    function documentHandler(e){
                        if(el.contains(e.target)){
                            return false
                        }
                        if(binding.expression){
                            binding.value(e)
                        }
                    }
                    el.__vueClickOutside__=documentHandler;
                    document.addEventListener('click',documentHandler);
                },
                unbind(el,binding){
                    document.removeEventListener('click',el.__vueClickOutside__);
                    delete el.__vueClickOutside__;
                }
            }
        }
    }
    </script>
  • 相关阅读:
    Zuul转发请求时HttpHostConnectException can't cast to ZuulException问题解决方法
    mysql循环插入千万级数据
    ssh登录原理及免密登录配置
    mysql binlog抽取某个表的数据
    ssh方式请求gitlab需要密码解决方法
    linux使用shell脚本停止java进程
    centos7安装docker-ce
    FutureTask详解
    Boolean.getBoolean用法
    mysql对emoji的支持
  • 原文地址:https://www.cnblogs.com/sx00xs/p/11266213.html
Copyright © 2020-2023  润新知