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>

效果:
相关推荐
程序猿乐锅18 分钟前
面向对象练习:图书借阅系统里的封装、抽象类与多态
开发语言·前端·数据库·后端·python·学习·1024程序员节
老木避暑研究所23 分钟前
负氧离子数据的采集、清洗与可视化:一套可复用的环境监测数据分析模板
前端·人工智能·数据分析
计算机魔术师42 分钟前
AI 推翻了一个当了30年地基的假设,查的人恰好是立论者
前端
范同学~1 小时前
项目添加水印
java·前端·javascript
鬼手点金1 小时前
缓存作为架构约束
开发语言·前端·人工智能·python·microsoft·缓存·架构
月夏1 小时前
前端第一次接自己的后端:mock 切真接口踩了 2 个坑,组件只改了一行 import
前端·后端·node.js
IT_陈寒1 小时前
React实战技巧总结:如何优雅处理复杂列表的渲染卡顿问题?
前端·人工智能·后端
ZoeLandia1 小时前
React11:数据请求与 TanStack Query
前端·react.js·typescript·react
软件技术NINI1 小时前
基于PHP和MySQL的快递代收点管理系统的设计与实现
开发语言·javascript·数据库·mysql·毕业设计·php·毕设
前端架构师-老李1 小时前
HTML与CSS基础第二课—初识HTML
前端·css·html