【问题标题】:Global call to the notification function in VUEJSVUEJS中通知函数的全局调用
【发布时间】:2019-07-31 18:38:56
【问题描述】:

我想做一个基于vue-notification组件的消息传递全局函数

我可以从所需的组件调用一个简单的警报

notification.js

export function notifAlert(message)  {
    alert(message)
}

在 text.vue 页面中

import { notifAlert } from '@/utils/notification'
export default { 
...
    methods: {
        onButtonClick() {
            notifAlert('1123');
        }
    }
}

但我不知道如何连接 vue-notification 以将它们也称为简单消息

notification.js

import VueNotifications from "vue-notifications";

export function notifAlert(messageText)  {
    notifications: {
        showSuccessMsg(): {
            type: VueNotifications.types.success,
            title: "Success",
            message: messageText
        },
        showInfoMsg: { ... },
        showWarnMsg: { ... },
        showErrorMsg: { ... },
    }
}

以及如何在方法中调用showSuccessMsg(文本)等?

【问题讨论】:

    标签: javascript node.js vue.js


    【解决方案1】:

    【讨论】:

    • 太好了,这正是我需要的,但 type: VueNotifications.types.success, 不需要在 AlertMixin.js 中使用?
    • 我使用了一个名为 mini-toastr 的单独插件(它位于 GitHub 上的 vue-notifications 文档中)。试试那个,看看它是否有效。谢谢!!
    • 我在 vue 页面上有这个错误TypeError: this.showSuccessMsg is not a function
    • 此链接不适合您吗?首先,我需要查看您正在编写的代码。确保将答案标记为已接受,我们可以在此线程之外聊天,因为您似乎遇到了新错误。codesandbox.io/s/github/oze4/vue-mixin-notifications-poc/tree/…
    猜你喜欢
    • 2018-01-22
    • 2019-04-24
    • 1970-01-01
    • 2017-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-28
    • 2016-07-29
    相关资源
    最近更新 更多