javascript - 在 Vue 之外使用 Buefy 组件
问题描述
如何在 Vue 组件之外创建Buefy 通知?例如,我定义了以下 axios 拦截器,并尝试使用 Buefy 通知:
import axios from "axios";
import { Notification } from "buefy/dist/components/notification";
axios.interceptors.response.use(
response => {
if (response.data.flash) {
Notification.open(response.data.flash);
}
return response;
},
error => {
if (error.response) {
Notification.open(error.response.data.flash);
return Promise.reject(error.response);
}
}
);
export default axios;
这导致控制台中出现此错误:
[Vue 警告]:v-on 处理程序中的错误(Promise/async):“TypeError:无法读取未定义的属性 'open'”
我究竟做错了什么?
解决方案
好的,发布后不久就找到了答案。把问题和答案放在一起,以防万一其他人遇到问题。显然,import { Notification } from "buefy/dist/components/notification"
这是一种旧的导入方式,而应该像这样导入:
import { NotificationProgrammatic as Notification } from "buefy";
推荐阅读
- r - 基于多个条件匹配两个数据帧的行
- python - 你好!如何使这个简单?我是 python 新手 :)
- python - Pytesseract - 图像上的 OCR,带有不同颜色的文本
- regex - 如何编写 SED 脚本以使用正则表达式根据用户输入替换文件中存在的版本代码
- javascript - 在另一台机器上启动反应应用程序
- coq - 错误“战术失败:关系 (fun xy : BloodType => x <> y) 不是声明的自反关系。” 在证明关于函数的定理时
- architecture - 消息持久化系统设计题
- angular - 如何通过 IP 地址访问 API
- python - ValueError:无法将 DataFrame 与类型的实例合并
- python - win10如何卸载python包