我有一个验证良好的 Nuxtjs 应用程序。但我需要用户详细信息才能自动填写表格。我看到应用程序在每次重新加载时都会调用 /user 端点。我想在其回调中插入一个 $store 以将用户数据存储在 $store 中。
computed: {
getUser () {
return this.$store.state.user.user;
}
},
methods: {
setUser (data) {
this.$store.commit('user/add', data)
},
}
NUXT 配置:
auth: {
strategies: {
local: {
endpoints: {
login: {
url: '/auth/login',
method: 'post',
propertyName: 'access_token'
},
logout: {
url: '/auth/logout',
method: 'post'
},
user: {
url: '/auth/user',
method: 'get',
propertyName: false
},
tokenRequired: true
}
}
}
}
是否可以拦截 $auth.fetchUser 或 $auth 用于在每次重新加载时获取 api/user 端点的任何方法?