绵阳动力网站建设

vue3无法显示element-plus的原因及解决办法

时间:2024-04-07

最近在用VUE3做网站建设项目时原本想使用el-tree做目录,结果找了很久的原因都无法显示,并且没有任何报错,但是在调试的过程中发现el-tree使用的数据是对象形式的


vue3无法显示element-plus的原因及解决办法

并且还报了el-tree组件无法解析

runtime-core.esm-bundler.js:38 [Vue warn]: Failed to resolve component: el-tree If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.


刚开始以为需要解析数据,但是其他人都可以正常使用,所以尝试放其他组件,结果其他组件也都无法使用,那么很有可能是挂载出现问题

因为将所有需要挂载使用的变量放在了一个use里导致的,还是得多熟悉才行

vue3无法显示element-plus的原因及解决办法

正确使用方法:

vue3无法显示element-plus的原因及解决办法

vue3使用Element-plus的图标

首先安装Element-Plus-icon

# 选择一个你喜欢的包管理器
 
# NPM
$ npm install @element-plus/icons-vue
# Yarn
$ yarn add @element-plus/icons-vue
# pnpm
$ pnpm install @element-plus/icons-vue

使用方法:

Element-Plus-icon官方文档链接

https://element-plus.org/zh-CN/component/icon.html#icon-collection

在main.ts中引入Element-Plus-icon

import * as ElementPlusIconsVue from '@element-plus/icons-vue'
 
Object.keys(ElementPlusIconsVue).forEach((key) => {
    app.component(key, ElementPlusIconsVue[key])
})

第一种直接点击图标复制<el-icon>

<el-icon><ArrowRight /></el-icon>

第二种通过icon="el-icon-plus" 

<el-button type="success" icon="el-icon-plus" >
    1111
</el-button>

第三种通过SVG

<template>
  <div style="font-size: 20px">
    <!-- 由于SVG图标默认不携带任何属性 -->
    <!-- 你需要直接提供它们 -->
    <Edit style="width: 1em; height: 1em; margin-right: 8px" />
    <Share style="width: 1em; height: 1em; margin-right: 8px" />
    <Delete style="width: 1em; height: 1em; margin-right: 8px" />
    <Search style="width: 1em; height: 1em; margin-right: 8px" />
  </div>
</template>

好了,通过以上代码就可以解决vue3无法显示element-plus的问题了,看完后喜欢的话记得收藏哦!

Copyright © 绵阳动力网站建设 www.kf51.cn All Rights Reserved 蜀ICP备08100083号

客服微信
客服微信
0816-6339181
客服微信
my_dongli