码迷,mamicode.com
首页 > 其他好文 > 详细

在element-ui组件注册之前,对其进行调整

时间:2020-07-03 15:51:48      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:attrs   dex   exp   属性   template   点击   场景   function   lis   

 拿button组件举例

 

 

 技术图片

 

 

 button.vue     v-bind="$attrs"  让子组件拥有父组件所有的attr属性 (props除外)   v-on="$listeners"   让子组件拥有所有父组件的事件(这个必须有,否则点击父组件不会触发事件)

<template>
    <Button 
        v-bind="$attrs"
        v-on="$listeners">
        <slot></slot>
    </Button>
</template>

<script>
import {Button} from "element-ui";
export default {
    name:"el-button",
    components:{
        Button
    },
    data(){
        return{

        }
    }
}
</script>

 

index.js

import elButton from "./button.vue"


elButton.install = function(Vue) {
    Vue.component(elButton.name, elButton);
};

export default elButton;

然后在main.js中引入:

import elButton from "@/ai-comp/el-button/index.js"

注册:

Vue.use(elButton)

这种场景适合在老项目中对项目中已经使用的组件进行二次封装,这种方式不会影响以前的二次封装!!!

 

 

 

 

在element-ui组件注册之前,对其进行调整

标签:attrs   dex   exp   属性   template   点击   场景   function   lis   

原文地址:https://www.cnblogs.com/fqh123/p/13230385.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!