代码之家  ›  专栏  ›  技术社区  ›  yierstem

无法访问内部的Buefy组件。beforeach()

  •  1
  • yierstem  · 技术社区  · 7 年前

    我正在尝试从Buefy访问Toast组件,以便在每次有人试图访问仅授权视图时显示错误:

    // ...
    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。

    1 回复  |  直到 7 年前
        1
  •  3
  •   yierstem    7 年前

    我解决了这个问题。

    我得到了$toast方法 Vue.prototype.$toast 因为我装了 Vue.use(Buefy)

    谢谢关注。

    推荐文章