Vuejs2 我必须以何种格式将数据与服务器表一起返回到vue-tables-2
在我的vue/cli 4/Bootstrap 4.3应用程序中,我使用vue-tables-2和读取服务器表 在这里实现 从服务器端(laravel 6)返回:Vuejs2 我必须以何种格式将数据与服务器表一起返回到vue-tables-2,vuejs2,vue-tables-2,Vuejs2,Vue Tables 2,在我的vue/cli 4/Bootstrap 4.3应用程序中,我使用vue-tables-2和读取服务器表 在这里实现 从服务器端(laravel 6)返回: return response()->json([ 'data' => $activityLogs, 'count' => $activity_logs_count ], 200
return response()->json([
'data' => $activityLogs,
'count' => $activity_logs_count
], 200);
在控制台中,我看到返回的数据:
但在控制台中我有错误:
vue-tables-2:无效的“计数”属性。预期数量,未定义
...
set data.js?7175:11计数等于未定义
...
vue.runtime.esm.js?2b0e:619[vue warn]:渲染中出错:“TypeError:props.data.forEach不是函数”
...
发现于
--->
vue.runtime.esm.js?2b0e:1888类型错误:props.data.forEach不是函数
默认情况下(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"
...
表格选项:{
//请参阅选项API
请求函数(数据){
this.is_page_loaded=false
让credentialsConfig=JSON.parse(JSON.stringify(settingCredentialsConfig))
credentialsConfig.headers.Authorization='承载人'+此.$parent.$parent.currentLoggedUserToken
返回axios.get(this.url{
参数:数据
},credentialsConfig).catch(函数(错误){
console.log('requestFunction错误::')
控制台错误(错误)
})
}//请求函数:(数据)=>{
},
...
“axios”:“^0.19.0”,
“vue”:“^2.6.10”,
“vue-tables-2”:“^2.0.14”
哪种格式必须是返回数据的有效格式
谢谢!有相同的错误消息。我们可以通过修改响应来解决此问题:
requestFunction: function (data) {
return this.$http
.post(this.url, data)
.then((response) => {
return response.data
})
.catch(function (e) {
this.dispatch('error', e)
})
}
请求中的承载令牌是否有401错误?我询问了开发人员,但失败。必须删除此组件。。。
requestFunction: function (data) {
return this.$http
.post(this.url, data)
.then((response) => {
return response.data
})
.catch(function (e) {
this.dispatch('error', e)
})
}