在按需引入通知类组件(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"
}
]]]
}
Message和Notification在Vue.use(Message) Vue.use(Notification)的时候就会弹一次,它们俩不要用Vue.use(),在你的组件里直接使用就行了