1

I am trying to call the fetch method on a data source created with a vue wrapper.

The error is [Vue warn]: Error in mounted hook: "TypeError: this.$refs.datasource.fetch is not a function" So my question is how can I call methods from the $refs object.

I made a stackblitz here

<body>
    <div id="vueapp" class="vue-app">
        <kendo-datasource ref="datasource" :data="dataSourceArray">
        </kendo-datasource>
    </div>
</body>

new Vue({
    el: '#vueapp',
    data: function() {
        return {
            dataSourceArray: [
                { text: 'Albania', value: '1' },
                { text: 'Andorra', value: '2' },
                { text: 'Armenia', value: '3' },
                { text: 'Austria', value: '4' },
                { text: 'Azerbaijan', value: '5' },
                { text: 'Belarus', value: '6' },
                { text: 'Belgium', value: '7' }
            ]
        }
    },
    mounted: function () {
      this.$refs.datasource.fetch()//<== error here
    }
})
ryeMoss
  • 4,303
  • 1
  • 15
  • 34
Padhraic
  • 5,112
  • 4
  • 30
  • 39

1 Answers1

1

The ref you are getting is the entire <kendo-datasource> component, which does not directly have a fetch() method. I believe what you are trying to do is get the kendoDataSource within the component and call the fetch method on it, which would be:

this.$refs.remoteDatasource.kendoDataSource.fetch();

modifying your example to see it in action:

    <kendo-datasource 
        ref="datasource" 
        :data="dataSourceArray" 
        :type="'odata'"
        :transport-read-url="'https://demos.telerik.com/kendo-ui/service/Northwind.svc/Customers'">
    </kendo-datasource>

this.$refs.remoteDatasource.kendoDataSource.fetch(function(){
    var data = this.data();
    console.log(data[0]);
    });
}
ryeMoss
  • 4,303
  • 1
  • 15
  • 34
  • Thanks, that worked great. While I was googling I also found another way to get the `kendoDataSource` object by calling `this.$refs.datasource.kendoWidget()` – Padhraic Dec 18 '18 at 05:55