【发布时间】:2020-08-25 11:31:59
【问题描述】:
如何在 Vue 组件之外创建 Buefy notification?例如,我定义了以下 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: Cannot read property 'open' of undefined”
我做错了什么?
【问题讨论】:
标签: javascript vue.js buefy