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

 拿button组件举例

 

 

 

 

 

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

 

复制代码
<template>
    <Button 
        v-if="pagePermission[$attrs.name] != false"
        :disabled="disabled"
        v-bind="$attrs"
        v-on="$listeners">
        <slot></slot>
    </Button>
</template>

<script>
import {Button} from "element-ui";
import { mapState } from 'vuex';
export default {
    name:"el-button",
    components:{
        Button
    },
    props:{
        disabled:{
            // 按钮是否可以点击
            type:Boolean,
            default:false
        }
    },
    computed:{
        ...mapState(['pagePermission']),
    }
}
</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)

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

 

 

 

 

posted @   古墩古墩  Views(701)  Comments(0Edit  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示