这是我构建的最小页面上的element-plus消息框的外观:
我希望它看起来像X1 E0 F1 X。
我使用Vue和vite以及ElementPlus。我从vite和element plus文档中复制了设置。我玩了很多其他元素,他们都正确渲染。可以重现问题的最小App.vue
组件:
<template>
<el-button text @click="open">Click to open the Message Box</el-button>
</template>
<script setup>
import { ElMessageBox } from 'element-plus'
const open = () => {
ElMessageBox.alert('This is a message', 'Title', {
confirmButtonText: 'OK'
})
}
</script>
我的vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
})
],
base: ''
})
页面很小:
<!DOCTYPE html>
<title>Vite + Vue</title>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
剧本也是如此:
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')
最后是package.json
:
{
"name": "v2",
"private": true,
"version": "0.0.0",
"main": "main.js",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"start": "electron ."
},
"dependencies": {
"electron": "^20.0.2",
"element-plus": "^2.2.12",
"vue": "^3.2.37"
},
"devDependencies": {
"@vitejs/plugin-vue": "^3.0.2",
"unplugin-auto-import": "^0.11.1",
"unplugin-vue-components": "^0.22.4",
"vite": "^3.0.6"
}
}
2条答案
按热度按时间ua4mk5z41#
我得说文档没有很好地解释它https://element-plus.org/en-US/guide/quickstart.html
当使用
ElMessage
或ElMessageBox
时,它们的样式 * 可能 * 需要手动导入。快速启动/按需导入部分没有说明它,所有其他元素都是开箱即用的,所以有点令人困惑。toe950272#
如果您已经使用了“unplugin-auto-import/vite”和“unplugin-vue-components/vite”,则不需要这样做:
从'element-plus'导入{ ElMessageBox };