错误是Vue警告:挂载钩子中的错误:"TypeError: this.$refs.datasource.fetch不是函数“,所以我的问题是如何从$refs对象调用方法。
我做了一个stackblitz 这里
<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
}
})发布于 2018-12-18 05:16:53
您得到的参考文件是整个<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]);
});
}https://stackoverflow.com/questions/53826394
复制相似问题