【问题标题】:In which format have I to return data to vue-tables-2 with Server Table我必须以哪种格式使用 Server Table 将数据返回到 vue-tables-2
【发布时间】:2020-08-02 12:57:25
【问题描述】:

在我的 vue/cli 4 / 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" 

哪种格式必须是返回数据的有效格式?

谢谢!

【问题讨论】:

    标签: vuejs2 vue-tables-2


    【解决方案1】:

    有同样的错误信息。能够通过修改响应来解决它:

        requestFunction: function (data) {
          return this.$http
            .post(this.url, data)
            .then((response) => {
              return response.data
            })
            .catch(function (e) {
              this.dispatch('error', e)
            })
        }
    

    【讨论】:

    猜你喜欢
    • 2021-05-16
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    • 2019-03-08
    • 1970-01-01
    • 2015-02-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多