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 \

问题分析:

使用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>

效果:
相关推荐
海天胜景2 小时前
vue3 el-table动态表头
javascript·vue.js·elementui
G_whang2 小时前
jenkins自动化部署前端vue+docker项目
前端·自动化·jenkins
凌辰揽月4 小时前
AJAX 学习
java·前端·javascript·学习·ajax·okhttp
然我6 小时前
防抖与节流:如何让频繁触发的函数 “慢下来”?
前端·javascript·html
鱼樱前端6 小时前
2025前端人一文看懂 Broadcast Channel API 通信指南
前端·vue.js
烛阴6 小时前
非空断言完全指南:解锁TypeScript/JavaScript的安全导航黑科技
前端·javascript
鱼樱前端6 小时前
2025前端人一文看懂 window.postMessage 通信
前端·vue.js
快乐点吧7 小时前
【前端】异步任务风控验证与轮询机制技术方案(通用笔记版)
前端·笔记
pe7er7 小时前
nuxtjs+git submodule的微前端有没有搞头
前端·设计模式·前端框架
七月的冰红茶7 小时前
【threejs】第一人称视角之八叉树碰撞检测
前端·threejs