首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用-2\f25 Server Table -2\f6将数据返回到-2\f25 vue-tables-2 \f6的格式

使用-2\f25 Server Table -2\f6将数据返回到-2\f25 vue-tables-2 \f6的格式
EN

Stack Overflow用户
提问于 2020-04-20 13:02:24
回答 1查看 288关注 0票数 0

在我的vue/CLI4/ Bootstrap 4.3应用程序中,我使用了vue-tables-2并在此处读取服务器表实现https://matanya.gitbook.io/vue-tables-2/server-table

在服务器端(Laravel 6),我返回:

代码语言:javascript
复制
        return response()->json([
            'data'                 => $activityLogs,
            'count'                => $activity_logs_count
        ], 200);

在控制台中,我看到返回的数据:https://imgur.com/a/2iGUfKS

代码语言:javascript
复制
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文件中,我有:

代码语言:javascript
复制
        <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" 

对于返回的数据,哪种格式必须有效?

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2020-05-13 20:39:02

有相同的错误信息。能够通过修改响应来解决此问题:

代码语言:javascript
复制
    requestFunction: function (data) {
      return this.$http
        .post(this.url, data)
        .then((response) => {
          return response.data
        })
        .catch(function (e) {
          this.dispatch('error', e)
        })
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61315419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档