element ui 按需引入出现问题

在按需引入通知类组件(Message、Notification)时,在页面加载后没有进行任何操作,但是会自动弹出一次空的通知框
图片描述

图片描述
(刚加载时)

但是组件本身使用正常
图片描述
(点击之后正常使用)

// main.js
...
import {
  Button,
  Message
} from 'element-ui'
Vue.use(Button)
Vue.use(Message)

Vue.prototype.$message = Message
...
// Message.vue
<template>
  <el-button type="primary" @click="handleClick">点我</el-button>
</template>

<script>
export default {
  methods: {
    handleClick() {
      this.$message('你点击了我');
    }
  }
};
</script>
// .babelrc
{
  "presets": [
    ["env", {
      "modules": false
    }],
    "stage-2"
  ],
  "plugins": [["component", [
    {
      "libraryName": "element-ui",
      "styleLibraryName": "theme-chalk"
    }
  ]]]
}
阅读 9.5k
2 个回答

Message和Notification在Vue.use(Message) Vue.use(Notification)的时候就会弹一次,它们俩不要用Vue.use(),在你的组件里直接使用就行了

新手上路,请多包涵

同遇此奇葩问题,
方案:Vue.use(Message)直接更改为

eg: Vue.prototype.$message = Message;
    Vue.prototype.$msgbox = MessageBox;
    Vue.prototype.$confirm = MessageBox.confirm;
 调用:this.$confirm... 即可
    
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题