【问题标题】:vue.js Toast is not defined(while using mint-ui)vue.js Toast 未定义(使用 mint-ui 时)
【发布时间】:2018-08-27 08:03:34
【问题描述】:

toast 是 mint-ui 组件,我已经导入 mint-ui,但是在 vue 实例中使用 toast 时会报错?为什么?

import Vue from 'vue';
import MintUi from 'mint-ui';

import 'mint-ui/lib/style.css'

Vue.use(MintUi);

new Vue({
    el:'#app',
    render:(creater)=> creater(app),
    created(){
        new Toast('hello')  //toast is not defined
    }
})

【问题讨论】:

    标签: vue.js webpack


    【解决方案1】:

    您需要从 Mint UI 导入 Toast。 将import MintUi from 'mint-ui'; 更改为以下。

    import MintUi, { Toast } from 'mint-ui';
    

    【讨论】:

    • 但是 import MintUi from 'mint-ui' 是指从'mint-ui' 导入所有组件,所以 MintUi 会包含 toast,我可以这样理解吗?
    • 当然,你用import MintUi from 'mint-ui';导入了MintUi,但是没有声明Toast。因此,您应该通过在导入时写入来获得“Toast”。如果你想在没有声明的情况下使用 Toast,我想你可以这样使用它。 new MintUi.Toast('hello')
    • new MintUi.Toast('hello''') 只是在当前页面使用,在其他页面使用,例如app.vue,会报错'MintUi' is not defined ,不知道为什么会出现这个错误
    • 可能是作用域引起的?
    • 请先检查此链接。 mint-ui.github.io/docs/#/en2/toast
    猜你喜欢
    • 2022-09-23
    • 2018-09-19
    • 2019-02-23
    • 2019-10-09
    • 1970-01-01
    • 2018-07-28
    • 2023-03-03
    • 2017-08-27
    • 2016-08-09
    相关资源
    最近更新 更多