I recently created a minimal page and integrated the Element-Plus message box. However, the appearance of the message box was different from what I expected based on the Element-Plus documentation.
My setup includes Vue, Vite, and ElementPlus. I followed the instructions from the Vite and Element Plus documentation to set up my project. Interestingly, other elements render correctly except for the message box. Here is a snippet of the minimal App.vue component that demonstrates the issue:
<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>
Here is my 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'
export default defineConfig({
plugins: [
vue(),
AutoImport({
resolvers: [ElementPlusResolver()],
}),
Components({
resolvers: [ElementPlusResolver()],
})
],
base: ''
})
The structure of the page is simple:
<!DOCTYPE html>
<title>Vite + Vue</title>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
And the script:
import { createApp } from 'vue'
import App from './App.vue'
createApp(App).mount('#app')
Lastly, here is my package.json configuration:
{
"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"
}
}