按需引入iview的Message全局提示组件。
import {Alert,Icon,Button,Modal,Tree,Message,} from 'iview';
import 'iview/dist/styles/iview.css'
Vue.component('Modal',Modal);
Vue.component('Tree',Tree);
Vue.component('Button',Button);
Vue.component('Icon',Icon);
Vue.component('Alert',Alert);
看了官网的教程iview Message全局提示组件
通过直接调用以下方法来使用组件:
this.$Message.info(config)
this.$Message.success(config)
this.$Message.warning(config)
this.$Message.error(config)
this.$Message.loading(config)
然后我在我需要的地方使用上述代码
...
}else{
console.log("检查未选项");
this.$Message.error('检查未选项');
}
...
报错
[Vue warn]: Error in event handler for "click": "TypeError: Cannot read property 'error' of undefined"
found in
---> <MdButton>
<Upload> at src\components\upload.vue
<App> at src\App.vue
<Root>
warn @ vue.esm.js?efeb:571
logError @ vue.esm.js?efeb:1689
globalHandleError @ vue.esm.js?efeb:1684
handleError @ vue.esm.js?efeb:1673
Vue.$emit @ vue.esm.js?efeb:2455
click @ vue-material.js?2e0c:12
invoker @ vue.esm.js?efeb:1943
fn._withTask.fn._withTask @ vue.esm.js?efeb:1778
vue.esm.js?efeb:1693 TypeError: Cannot read property 'error' of undefined
at VueComponent.subimtBtn (upload.vue?b0d8:165)
at boundFn (vue.esm.js?efeb:186)
at Proxy.invoker (vue.esm.js?efeb:1943)
at Proxy.Vue.$emit (vue.esm.js?efeb:2453)
at click (vue-material.js?2e0c:12)
at invoker (vue.esm.js?efeb:1943)
at HTMLButtonElement.fn._withTask.fn._withTask (vue.esm.js?efeb:1778)
请教各路大佬..谢谢
import {Alert,Icon,Button,Modal,Tree,Message,} from 'iview';
import 'iview/dist/styles/iview.css'
Vue.component('Modal',Modal);
Vue.component('Tree',Tree);
Vue.component('Button',Button);
Vue.component('Icon',Icon);
Vue.component('Alert',Alert);
你这里贴的代码没有把message注册为全局组件?
babel-plugin-import插件装了没?配置了没?
按需引用