zoukankan      html  css  js  c++  java
  • vue 组件

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
            <script type="text/javascript" src="js/vue.js"></script>
        </head>
        <body>
            <div id="app">
                <h2>自定义的下拉框</h2>
                <custom-select btn='查询' v-bind:list="list1"></custom-select>
                <h2>自定义的下拉框2</h2>
                <custom-select btn='搜索' v-bind:list="list2"></custom-select>
            </div>
            
        </body>
        <script>
            //注册组件
            Vue.component("custom-select",{
                data:function(){
                    return{
                        selectShow:false,
                        val:""
                    }
                },
                props:["btn","list"],
                template:`
                    <section class="warp">
                        <div class="searchIpt clearFix">
                            <div class="clearFix">
                                <input type="text" class="keyWord" :value="val" @click="selectShow=!selectShow"/>
                                <input type="button" :value="btn" />
                                <span></span>
                            </div>
                            <custom-list 
                                v-show="selectShow" 
                                :list=list
                                v-on:receive="changeValueHandle"
                            ></custom-list>
                        </div>
                    </section>
                  `,
                  methods:{
                      changeValueHandle(value){
                          this.val=value;
                      }
                  }
            })
            Vue.component("custom-list",{
                props:["list"],
                template:
                `
                <ul class="list" v-show='selectShow'>
                    <li v-for="item of list" @click="selectValueHandle(item)">{{item}}</li>
                </ul>
                `,
                methods:{
                    selectValueHandle:function(item){
                        //在子组件中有交互
                        //告知父级,改变val的值,需要触发一个自定义事件
                        this.$emit("receive",item)
                        
                    }
                }
            })
            
            new Vue({
                el:"#app",
                data:{
                    list1:["北京","上海","杭州","广州","兰州",],
                    list2:["20-05-06","20-06-30","20-07-05","20-08-12","20-08-23",]
                }
            })
        </script>
    </html>

  • 相关阅读:
    有关phpmailer的详细介绍及使用方法
    威盾解密
    PHP正则表达式验证是否含有中文
    php防止重复提交表单
    simplexml 对xml的增删改操作
    Javascript正则表达式完全学习手册
    利用JS做到隐藏div和显示div
    js控制div显示与隐藏
    后台登陆地址
    MVC 自定义路由
  • 原文地址:https://www.cnblogs.com/gxywb/p/13581150.html
Copyright © 2011-2022 走看看