我的Vue应用程序在移动浏览器上的使用存在问题。我在使用JWT进行身份验证/许可的Django后端上具有受保护的API路由。进行身份验证时,我将JWT保存到localStorage和Vuex,并将其作为标头传递给Vuex存储中的每个请求(使用axios)。这一切在我的笔记本电脑上都可以正常工作,但是在移动设备上访问我的网站时却无法正常工作。使用手机(iOS 12)访问网站时,我在日志中看到401未经授权的错误代码,因此我假设未将令牌添加为标头。这是我用来附加标题的代码:
import axios from 'axios';
import store from '../store';
const apiCall = axios.create();
apiCall.interceptors.request.use(
config => {
if (store.getters.isAuthenticated) {
// Take the token from the state and attach it to the request's headers
config.headers.Authorization = `JWT ${store.getters.getToken}`;
}
return config
},
error => {
Promise.reject(error)
}
)
export default apiCall;
这是我的开发依赖项:
"devDependencies": {
"@vue/cli-plugin-babel": "^3.0.5",
"@vue/cli-plugin-e2e-nightwatch": "^3.0.5",
"@vue/cli-plugin-eslint": "^3.0.5",
"@vue/cli-plugin-pwa": "^3.0.5",
"@vue/cli-plugin-unit-jest": "^3.0.5",
"@vue/cli-service": "^3.0.5",
"@vue/eslint-config-airbnb": "^3.0.5",
"@vue/test-utils": "^1.0.0-beta.20",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^23.0.1",
"node-sass": "^4.11.0",
"sass-loader": "^7.0.1",
"vue-template-compiler": "^2.5.17"
},
是否需要添加一些内容到devDependencies
中,以便可以从移动设备访问Posts
?