微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用@websanova/vue-auth 在 Vue 中未定义 $auth

如何解决使用@websanova/vue-auth 在 Vue 中未定义 $auth

我正在尝试使用 Vue.js 和 Laravel 作为后端创建 SPA。我在后端使用 tymon/jwt-auth 进行 JWT 身份验证。

我在 Login.vue 中找不到 $auth。

我像这样在 app.js 中包含了 @websanova/vue-auth

...
import {createAuth}          from '@websanova/vue-auth/dist/v3/vue-auth';
import driverAuthBearer      from '@websanova/vue-auth/dist/drivers/auth/bearer.esm.js';
import driverHttpaxios       from '@websanova/vue-auth/dist/drivers/http/axios.1.x.esm.js';
import driverRouterVueRouter from '@websanova/vue-auth/dist/drivers/router/vue-router.2.x.esm.js';
...
var auth = createAuth({
    plugins: {
        http: axios,router: router
    },drivers: {
        http: driverHttpaxios,auth: driverAuthBearer,router: driverRouterVueRouter,},options: {
        rolesKey: 'type',notFoundRedirect: {name: 'user-account'},}
});

Vue.use(auth);

但这给了我Uncaught TypeError: vue.reactive is not a function

我按照 @websanova/vue-auth site

中的指示遵循了最新实施

我也尝试了一些旧教程 thisthis 使用包的 v2,但在这种情况下 this.$auth 在 Login.vue 中是未定义的

这是我完整的 app.jsLogin.vue

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。