vue定义全局组件,不需要在文件中引入,直接使用

1.首先写一个组件

<template>
    <div class="top-da">
        <div class="i-con">
            <i class="el-icon-collection-tag"></i>
        </div>
        <div class="title">
            <slot></slot>
        </div>
    </div>
</template>
<style scoped lang="scss">
.top-da{
    box-sizing: border-box;
    height: 48px;
    line-height: 48px;
    background: #f9f9f9;
    border-bottom: 1px solid #E4E7ED;
    margin: 0;
    padding: 0 8px;
    display: flex;
    align-items: center;
    .i-con{
        border-radius: 50%;
        height: 2rem;
        width: 2rem;
        background-color:#409EFF ;
        line-height: 2rem;
        color:#fff;
        text-align: center;
        font-size: 14px;
        font-weight: 400;
        .el-icon-collection-tag:before{
            content:"\E765";
        }
    }
    .title{
        margin-left:1rem;
        font-size: 14px;
        color: #303133;
    }
    
}
</style>

2.在创建一个index.js文件

import topDa from '@/components/publicComponent/component/topDa.vue'
import nav from '@/components/publicComponent/component/nav.vue'
let components = {
    install:function(Vue){
        Vue.component("topDa",topDa)
    }
}
export default components;

3.在main.js中引入然后使用vue.use()注册或者使用

import components from '@/components/publicComponent/index.js'
Vue.use(components);

4.在组件中使用

<top-da>
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>活动管理</el-breadcrumb-item>
          <el-breadcrumb-item>活动列表</el-breadcrumb-item>
          <el-breadcrumb-item>活动详情</el-breadcrumb-item>
        </el-breadcrumb>
      </top-da>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值