我正在尝试从 Buefy 访问 Toast 组件以在每次有人尝试访问仅授权 View 时显示错误:
// ...
import { Toast } from 'buefy/dist/components/toast'
router.beforeEach((to, from, next) => {
// ...
if (to.matched.some(record => record.meta.requiresAuth)) {
if (!(store.state.isAuth)) {
Toast.open({
message: "Not authorized"
});
next({
path: '/login/',
})
} else {
next()
}
} else {
next()
}
}
但 Toast
未定义,我确实导入了 Buefy
并编写了 Vue.use(Buefy)
。
如何解决这个问题并访问这里的Toast。 提前致谢。
最佳答案
我解决了这个问题。
我从 Vue.prototype.$toast
得到了 $toast 方法,因为我用 Vue.use(Buefy)
加载了它。
感谢关注。
关于javascript - 无法访问 .beforeEach() 中的 Buefy 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52448455/