This is how element-plus message box looks on a minimal page I built: enter image description here

我本以为它会在element-plus documentation号公路上出现.

我用的是VueviteElementPlus.我复制了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>

playbook 也是如此:

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"
  }
}

推荐答案

我要说的是,文档不能很好地解释这一点

当使用ElMessageElMessageBox时,需要手动导入它们的样式might.quick start / On-demand Import部分没有说明任何事情,而且所有其他元素都是开箱即用的,所以它有点令人困惑.

<template>
  <el-button text @click="open">Click to open the Message Box</el-button>
</template>

<script setup>
import { ElMessageBox } from 'element-plus';
import 'element-plus/es/components/message/style/css'; // this is only needed if the page also used ElMessage
import 'element-plus/es/components/message-box/style/css';

const open = () => {
  ElMessageBox.alert('This is a message', 'Title', {
    confirmButtonText: 'OK'
  })
}
</script>

Css相关问答推荐

我控制的自定义单选按钮无法重新 Select

Css-如何隐藏WP管理菜单上没有css类的第4<;li&>

设置项目的最大宽度和最大高度

臭虫?嵌套的css供应商前缀中断Chrome css解析

在最小和最大视口之间时具有固定值的 CSS 钳位

使用 Vuetify 的 sass 变量时出错

如何让 v-col 变成可滚动的?

这个 CSS :is() Select 器没有像我想象的那样工作

为什么删除 AnimatePresence framer.div 时会出现轻微卡顿?

同时实现渐变文本和闪光文本效果是否可行?

和号 (&) 作为 SASS @mixin 中的变量

热门制作渐变半红/半蓝?

包含tailwind 中固定纵横比框的内容

  • 元素上的子弹来自哪里?
  • 字体上的 Font-Awesome 错误 404

    如何使内容出现在固定的 DIV 元素下方?

    调用转发到 JSP 的 Servlet 时,浏览器无法访问/查找相关资源,如 CSS、图像和链接

    了解 Bootstrap 3 中的网格类( col-sm-# 和 col-lg-# )

    Unicode 通过 CSS :before

    堆叠半透明盒子的 colored颜色 取决于订单?