【问题标题】:How to use this.$notification of Ant Design (Vuejs) in .js file?如何在 .js 文件中使用 this.$notification of Ant Design (Vuejs)?
【发布时间】:2020-06-27 03:47:59
【问题描述】:

实际上我们在 .vue 文件中使用 this.$notification.open(opitons) 然后它会在我们的 web 应用程序中显示通知。但是我们如何在 .js 文件中使用 this.$notification.open(options) 。例如,我在 .js 文件中编写了外部函数,如果出现错误,它将显示通知。我尝试导入 Antd,然后使用 Antd.notification.open(opens)。此代码不起作用。

Ant Design Notification 链接在这里:https://www.antdv.com/components/notification/

【问题讨论】:

  • 你的js文件中也导入vue了吗?
  • 不,我不知道。现在,我尝试在 main.js 文件中使用它

标签: vue.js


【解决方案1】:

您可以直接在 .js 文件中导入来自 ant design 的通知 例如

从“ant-design-vue”导入{通知};

notification.error({ 消息:'错误!', 描述:err.response.data.message, 类:'错误' })

【讨论】:

    猜你喜欢
    • 2020-01-23
    • 2019-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-12
    • 2021-11-20
    • 2021-08-30
    相关资源
    最近更新 更多