当前位置: 首页 > news >正文

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 } = VuecreateApp({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} = Vueconst 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>
 

效果: 

http://www.lryc.cn/news/228186.html

相关文章:

  • sen2cor安装
  • 通付盾Web3专题 | SharkTeam:Web3安全实践与创新
  • ARM Linux 基础学习 / Ubuntu 下的包管理 / apt工具
  • springcloudalibaba入门详细使用教程
  • C# DirectoryInfo类的用法
  • IDEA常用快捷键大全(详解)
  • 设计模式之解释器模式
  • 粉够荣获淘宝联盟区域理事会常务理事,携手共铸淘客新生态
  • Python爬虫是否合法?
  • 3.2 IDAPro脚本IDC常用函数
  • 用python将csv表格数据做成热力图
  • 【程序基础】递归法
  • AI 绘画 | Stable Diffusion WebUI的基本设置和插件扩展
  • 如何用自然语言 5 分钟构建个人知识库应用?我的 GPTs builder 尝试
  • rabbitmq启动异常解决
  • OpenGL_Learn08(坐标系统与3D空间)
  • github私有仓库开发,公开仓库发布版本
  • 绿色低碳 数字未来-辽宁省建筑电气2023年学术年会-安科瑞 蒋静
  • day55
  • 如何安装Node.js? 创建Vue脚手架
  • ASP.NETWeb开发(C#版)-day1-C#基础+实操
  • LGSVL Python API 使用
  • 详解数据仓库之拉链表(原理、设计以及在Hive中的实现)
  • 使用Nodejs搭建简单的web网页并实现公网访问
  • C++学习第三十七天----第十章--对象和类
  • TikTok影响力经济:解锁社交媒体的商业机遇
  • 燃气管网监测系统|全面保障燃气安全
  • 第三章:人工智能深度学习教程-基础神经网络(第六节-ML深度学习层列表)
  • 福建科立讯通信 指挥调度管理平台RCE漏洞复现
  • 性能测试:Jenkins+Ant+Jmeter自动化框架的搭建方法