我是 Vuejs 2 的新手,目前正在做一个项目。我在用着vuetable-2形成一个数据表Vuejs 2.
我目前面临一个问题,无法使用属性 api-url、vuetable-2 检索数据。
但是,我可以使用 Axios 和全局 Axios 默认配置从服务器检索数据(将令牌传递到每个请求标头中).
错误图像 https://i.stack.imgur.com/SxExG.png
上图显示了 2 个部分:
1. 使用vuetable-2的api-url [错误403的那个,禁止使用]
2.使用axios GET请求【成功检索数据】
Vuetable-2 api-url(对服务器的 api 调用):
<vuetable
ref="vuetable"
api-url="http://localhost:3000/api/staffs"
:http-options = "httpOptions"
:load-on-start = "loadOnStart"
:fields="['userId', 'name', 'username']"
></vuetable>
axios的全局默认配置:
// Global axios default (config default that will be applied to every request)
var accessToken = window.localStorage.getItem('access_token')
axios.defaults.baseURL = 'http://localhost:3000/'
axios.defaults.headers.common['x-access-token'] = accessToken
我错过了什么吗? :-/
我只能假设在推送请求时 Axios 标头被 Vuetable 覆盖。您可以使用以下格式将它们提供给 vueTable:
<vuetable
ref="vuetable"
api-url="http://localhost:3000/api/staffs"
:http-options="{ headers: { 'x-access-token' : accessToken } }"
:load-on-start = "loadOnStart"
:fields="['userId', 'name', 'username']"
></vuetable>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)