vue 静态页面组件注册

请看这篇文章 http://blog.csdn.net/oak160/article/details/64920361

组件标签

 

<custom-select btn="查询" v-bind:list="list1"></custom-select>
 
用 is 把组件插入不标准标签
 
<table is="custom-select"></table>

props传数据

 

  组件内的数据必须是函数声明:

  例子

  data:function (){

  return name:obj.data

 }

 

 return 作用就是吧对象重新赋值,相当于赋值一样,给了name, 通俗一些就是 把obj.data 复制给了name:obj

 

例子

 

html:

 

<div id="app">
            <div style="float: left;">
                <h2>自定义的下拉框</h2>
                <custom-select btn="查询" v-bind:list="list1"></custom-select>
            </div>
            <div style="float:left;">
                <h2>自定义的下拉框2</h2>
                <custom-select btn="搜索" v-bind:list="list2"></custom-select>
            </div>
        </div>
 
 
//注册组件
            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){
                        //alert("我被触发了,值为:"+value);
                        this.val = value;
                    }
                }
            })
            Vue.component("custom-list",{
                props:["list"],
                template:`<ul class="list">
                            <li v-for="item of list" @click="selectValueHandle(item)">{{item}}</li>
                        </ul>`,
                methods:{
                    selectValueHandle:function(item){
                        //在子组件中有交互
                        //告知父级,改变val的值,需要出发一个自定义事件

                        this.$emit("receive",item);
                    }
                }
            })

转载于:https://www.cnblogs.com/blccy/p/8214864.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值