解决Failed to resolve import “@element-plus/icons-vue“ from “src\views\Home.vue“. Does the file exist?

02-29 1395阅读 0评论

解决在Vue3+Vite中使用Element-plus报错

一、安装镜像(可选)

使用阿里定制的cnpm命令行工具代替默认的npm,输入以下代码

解决Failed to resolve import “@element-plus/icons-vue“ from “src\views\Home.vue“. Does the file exist?,解决Failed to resolve import “@element-plus/icons-vue“ from “src\views\Home.vue“. Does the file exist?,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,使用,安装,配置,第1张
(图片来源网络,侵删)
npm install -g cnpm --registry=http://registry.npmmirror.com

二、解决报错

1.安装Element-plus

1.1在项目目录下执行:

cnpm install element-plus --save

1.2安装按需引入需要的插件:

cnpm install -D unplugin-vue-components unplugin-auto-import

1.3安装Element Icon(解决标题所言的报错)

cnpm install @element-plus/icons-vue

2.配置

2.1在Vite的配置文件中加入如下代码:

import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
// 引入插件
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
      imports: ['vue', 'vue-router']
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})

2.2执行 cnpm run dev 成功启动项目!

解决Failed to resolve import “@element-plus/icons-vue“ from “src\views\Home.vue“. Does the file exist?,解决Failed to resolve import “@element-plus/icons-vue“ from “src\views\Home.vue“. Does the file exist?,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,使用,安装,配置,第2张
(图片来源网络,侵删)
解决Failed to resolve import “@element-plus/icons-vue“ from “src\views\Home.vue“. Does the file exist?,解决Failed to resolve import “@element-plus/icons-vue“ from “src\views\Home.vue“. Does the file exist?,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,使用,安装,配置,第3张
(图片来源网络,侵删)

免责声明
本网站所收集的部分公开资料来源于AI生成和互联网,转载的目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

发表评论

快捷回复: 表情:
评论列表 (暂无评论,1395人围观)

还没有评论,来说两句吧...

目录[+]