在我的@ vue / cli 4.0.5应用程序中实现带服务器表的vue-tables-2组件然后看这个https://matanya.gitbook.io/vue-tables-2/server-table/custom-request-function
我尝试将添加的授权参数设置为要求类似:
<div id="activity_logs_data_table">
<v-server-table url="/adminarea/activity-logs-filter" :columns="columns" :options="tableOptions">
<span slot="edit" slot-scope="{row}">
<a v-on:click="viewActivityLog(row)" :class="'p-1 a_view_item_'+row.id">
<i :class="'i_link '+getHeaderIcon('view')" title="View activity log item"></i>
</a>
<a v-on:click="removeActivityLog(row.id, row.log_name)" :class="'p-1 a_delete_item_'+row.id">
<i :class="'i_link '+getHeaderIcon('remove')" title="Remove activity log item"></i>
</a>
</span>
<span slot="created_at" slot-scope="{row}">
{{ momentDatetime(row.created_at, jsMomentDatetimeFormat) }}
</span>
</v-server-table>
</div>
data() {
return {
activityLogs: [],
el: "#activity_logs_data_table",
columns: ['id', 'log_name', 'causer_id', 'causer_type', 'created_at', 'edit'],
tableOptions: {
requestFunction: (data) => {
console.log('requestFunction data::')
console.log(data)
this.is_page_loaded = false
this.credentialsConfig.headers.Authorization = 'Bearer ' + this.currentLoggedUserToken;
console.log('requestFunction this.credentialsConfig::')
console.log(this.credentialsConfig)
return axios.get(this.url, {
params: data
}, this.credentialsConfig ).catch(function (error) {
console.log('requestFunction error::')
console.error(error)
// this.dispatch('error', error );
});
} // requestFunction: (data) => {
但是我在控制台中看到错误:
TypeError: Cannot read property 'indexOf' of undefined
at buildURL (buildURL.js?30b5:62)
at dispatchXhrRequest (xhr.js?b50d:30)
at new Promise (<anonymous>)
at xhrAdapter (xhr.js?b50d:12)
at dispatchRequest (dispatchRequest.js?5270:52)
和带有调试功能的控制台的打印屏幕:https://prnt.sc/rtak15我看到查询参数为空...这可能是问题吗? axios.get中的参数无效吗?
"axios": "^0.19.0",
"vue": "^2.6.10",
"vue-tables-2": "^2.0.14"
谢谢!
我设法以以下方式运行请求:
requestFunction(data) {
let credentialsConfig= JSON.parse(JSON.stringify(settingCredentialsConfig))
credentialsConfig.headers.Authorization = 'Bearer ' + this.$parent.$parent.currentLoggedUserToken
return axios.get(this.url, {
params: data
}, credentialsConfig ).catch(function (error) {
console.error(error)
})
} // requestFunction: (data) => {
!