matfish2 / vue-tables-2

Vue.js 2 grid components
https://matanya.gitbook.io/vue-tables-2/
GNU General Public License v3.0
1.53k stars 305 forks source link

Uncaught (in promise) TypeError: Cannot read property 'data' of undefined #765

Closed jauharfuadi54 closed 4 years ago

jauharfuadi54 commented 4 years ago

My code is work well, I can get the data, but I got that error too. How to solve it? I am using Server-side. This is my code

 <v-server-table :columns="columns" :options="options">
          <div slot="action" slot-scope="{row}">
            <router-link
              :to="{name: 'rumah_sakit_edit', params: { id: row.id }}"
              class="btn btn-primary"
            >Edit</router-link>
            <button @click.prevent="del(row.id)" class="btn btn-danger">Delete</button>
          </div>
        </v-server-table>

And my vue

<script>
var config = {
  "PMI-API-KEY": "erpepsimprpimaiy"
};
export default {
  name: "user-profile",
  data() {
    return {
      columns: ["category_name", "category_description", "action"],
      options: {
        requestFunction: function(data) {
          console.log(data);
          return this.$http({
            url: "api/v1/news_category/datatable",
            method: "post",
            headers: config,
            data: data
          }).then(res => {
            this.data = res.data.data;
            console.log(this.data);
            // console.log(res);
          });
        },
};
</script>
matfish2 commented 4 years ago

your requestFunction should return the promise without the resolving then callback. Promise resolution is handled by the plugin (https://github.com/matfish2/vue-tables-2#custom-request-function). If you need to control the response handler you responseAdapter

jauharfuadi54 commented 4 years ago

your requestFunction should return the promise without the resolving then callback. Promise resolution is handled by the plugin (https://github.com/matfish2/vue-tables-2#custom-request-function). If you need to control the response handler you responseAdapter

I am using return Promise.resolve(this); and it is resolve that error