TypeError: this.$refs.datasource.fetch is not a function
TypeError: this.$refs.datasource.fetch is not a function
我正在尝试调用 fetch method on a data source created with a vue wrapper。
错误是[Vue warn]: Error in mounted hook: "TypeError: this.$refs.datasource.fetch is not a function" 所以我的问题是如何从 $refs 对象中调用方法。
我做了一个 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
}
})
您得到的 ref 是整个 <kendo-datasource>
组件,它不直接具有 fetch()
方法。我相信您要做的是在组件中获取 kendoDataSource 并在其上调用 fetch 方法,这将是:
this.$refs.remoteDatasource.kendoDataSource.fetch();
修改您的示例以查看其实际效果:
<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]);
});
}
我正在尝试调用 fetch method on a data source created with a vue wrapper。
错误是[Vue warn]: Error in mounted hook: "TypeError: this.$refs.datasource.fetch is not a function" 所以我的问题是如何从 $refs 对象中调用方法。
我做了一个 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
}
})
您得到的 ref 是整个 <kendo-datasource>
组件,它不直接具有 fetch()
方法。我相信您要做的是在组件中获取 kendoDataSource 并在其上调用 fetch 方法,这将是:
this.$refs.remoteDatasource.kendoDataSource.fetch();
修改您的示例以查看其实际效果:
<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]);
});
}