Html 引入element UI + vue3 报错Failed to resolve component: el-button

问题:Html 引入element UI + vue3 ,el-button效果不出来

复制代码
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <!-- import Vue before Element -->
<!--  <script src="https://unpkg.com/vue@2/dist/vue.js"></script>-->
  <script src="js/vue3.3.8/vue.global.js"></script>
  <!-- import JavaScript -->
  <!--  <script src="js/elementUI/index.js"></script>-->
  <script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
  <!-- import CSS -->
  <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">



</head>
<body>
<div id="app">
  <!-- 双大括号语法,可以直接拿到下面data中return 里面的数据 -->
  {{message}}
  <el-button type="success">成功按钮</el-button>
  <el-progress type="circle" :percentage="20"></el-progress>
</div>
</body>

<script>
 const { createApp, ref } = Vue
   createApp({
     setup() {
       const message = ref('Hello vue!')
       return {
         message
       }
     }
   }).mount('#app')

</script>
</html>

运行报错:

index.min.js:1 Uncaught TypeError: Cannot read properties of undefined (reading '$isServer')

Vue warn: Failed to resolve component: el-button

If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.

at <App>

问题分析:

使用vue2的话运行正常,应该是vue3与element UI不兼容。

Element UI是一款基于Vue2.x 的界面框架;Element Plus是一款基于Vue3.x 的界面框架;

解决

vue3的话,改用element Plus

源码:

注意:在挂载vue之前,要加载elementplus

app.use(ElementPlus)

复制代码
<html>
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1.0" />
  <script src="https://unpkg.com/vue@next"></script>
  <!-- import CSS -->
   <link rel="stylesheet" href="https://unpkg.com/element-plus/dist/index.css">
  <!-- import JavaScript -->
  <script src="https://unpkg.com/element-plus"></script>

  <title>Element Plus demo</title>
</head>
<body>
<div id="app">
  <el-button type="primary">{{ message }}</el-button>
  <el-progress :percentage="20" type="circle"></el-progress>
</div>
<script>

    const {createApp, ref} = Vue
  const app = createApp({
    setup() {
      const message = ref('Hello vue!')
      return {
        message
      }
    }
  })
  app.use(ElementPlus)
  app.mount('#app')

</script>
</body>
</html>

指定特定版:

<script src=''></script>

<link rel="stylesheet" href="https://unpkg.com/browse/element-plus@2.4.2/dist/index.css">

<script src='https://unpkg.com/element-plus@2.4.2/dist/index.full.js'></script>

效果:
相关推荐
锋行天下4 分钟前
langgraph 全栈项目(二)
前端·人工智能·后端
冬夜Zis1 小时前
顺着作用域链和 outer 指针,一次性看懂闭包底层逻辑
javascript
Ceelog1 小时前
Mac 上怎么找出并安全清理旧的 node_modules?(实测 304 个占 66.3 GB)
javascript
锋行天下1 小时前
langgraph全栈项目(一)
前端·人工智能·后端
叼烟扛炮1 小时前
[LangChain] 学习笔记(15):为什么你的重试没用——429、抖动、fallback 与熔断
java·服务器·前端
小码哥0682 小时前
智慧物业系统源码定制:公告发布范围与住户阅读记录设计
前端·javascript·vue.js·物业管理·物业系统·物业软件
Highcharts.js3 小时前
Highcharts直方图使用指南:如何根据派生数据创建直方图?
javascript·信息可视化·直方图·highcharts·图表开发·创建图表·派生数据
ZhengEnCi4 小时前
Express 企业级项目结构怎么组织:五层骨架、单向依赖和一份能跑的边界检查脚本
javascript·node.js·express
泯泷4 小时前
Cloudflare 出手抢 Astro:前端框架之战,底层逻辑变了
前端·javascript·前端框架