2017-06-22 48 views
1

我是Vuejs 2的新手,目前正在執行一個項目。我正在使用vuetable-2Vuejs 2中形成數據表。無法檢索使用vuetable-2的數據,在Vuejs 2

我目前正面臨一個問題,我無法使用屬性,api-url,vuetable-2檢索數據。

但是,我可以使用Axios和Global Axios Default Configs (將令牌傳遞給每個請求標頭)從服務器檢索數據。


Error Image

以上示出了該圖像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> 

愛可信全球默認配置:

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

上午我上遺漏了呢? : -/

回答

-1

從vuetable的源代碼http://cdn.jsdelivr.net/vue.table/1.5.3/vue-table.js (你可以搜索鍵workd「loadData」找到的地方。)

,我們可以知道,它是使用this.$http.get(url, this.httpData, this.httpOptions).then(function (response) { 從服務器檢索數據。

所以我只敢說你爲axios配置的頭文件不適用於vuetable,你能檢查由vuetable發送的請求頭文件的內容嗎?

我的意思是http://localhost:3000/api/staffs?sort=&XXX

+0

也許你可以參考這個問題補充攔截您vuetable的要求https://stackoverflow.com/questions/39665244/vue-resource-interceptor-for-auth-headers –