Problem: Html introduces element UI + vue3, but the el-button effect does not appear
<!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>
Running error:
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>
problem analysis:
If you use vue2, it runs normally. It should be that vue3 is not compatible with element UI.
Element UI is an interface framework based on Vue2.x; Element Plus is an interface framework based on Vue3.x;
solve
For vue3, use element Plus instead.
Source code:
Note: Before mounting vue, elementplus must be loaded
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>
Specify a specific version:
<link rel="stylesheet" href="https://unpkg.com/browse/[email protected]/dist/index.css">
<script src='https://unpkg.com/[email protected]/dist/index.full.js'></script>