如何在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处理程序中的错误(承诺/异步):“ TypeError:无法读取未定义的属性'open'”]
我在做什么错?
确定,在发布此答案后不久就想出了答案。以防万一其他人遇到问题,将问题留给答案。显然,import { Notification } from "buefy/dist/components/notification"
是一种旧的导入方式,应该这样导入:
import { NotificationProgrammatic as Notification } from "buefy";