在我的vue/CLI4/ Bootstrap 4.3应用程序中,我使用了vue-tables-2并在此处读取服务器表实现https://matanya.gitbook.io/vue-tables-2/server-table
在服务器端(Laravel 6),我返回:
return response()->json([
'data' => $activityLogs,
'count' => $activity_logs_count
], 200);在控制台中,我看到返回的数据:https://imgur.com/a/2iGUfKS
But in the console I have errors :
vue-tables-2: invalid 'count' property. Expected number, got undefined
...
set-data.js?7175:11 count equals undefined
...
vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in render: "TypeError: props.data.forEach is not a function"
...
found in
---> <RLTableBody>
<VtTableBody>
vue.runtime.esm.js?2b0e:1888 TypeError: props.data.forEach is not a function
at _default (VtTableBody.js?1a4e:36)我认为这是返回数据格式的问题。在vue文件中,我有:
<div id="activity_logs_data_table">
<v-server-table :url="apiUrl + '/activity-logs-filter'" :columns="columns" :options="tableOptions">
</v-server-table>
</div>
...
tableOptions: {
// see the options API
requestFunction(data) {
this.is_page_loaded = false
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.log('requestFunction error::')
console.error(error)
})
} // requestFunction: (data) => {
},
...
"axios": "^0.19.0",
"vue": "^2.6.10",
"vue-tables-2": "^2.0.14" 对于返回的数据,哪种格式必须有效?
谢谢!
发布于 2020-05-13 20:39:02
有相同的错误信息。能够通过修改响应来解决此问题:
requestFunction: function (data) {
return this.$http
.post(this.url, data)
.then((response) => {
return response.data
})
.catch(function (e) {
this.dispatch('error', e)
})
}https://stackoverflow.com/questions/61315419
复制相似问题