类型错误:this.$set 不是函数 [英] TypeError: this.$set is not a function
本文介绍了类型错误:this.$set 不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到此错误:未捕获(承诺)类型错误:this.$set 不是函数
这是代码:
export default {
data: function() {
return { movies: '' }
},
ready: function() {
this.showMovies()
},
methods: {
showMovies: function() {
this.$http.get(config.api.url + '/movies').then(function (response) {
this.$set('movies', response.data)
})
}
}
}
推荐答案
this.$set
不是示例代码中的函数的原因是因为 this
没有'不再引用 Vue ViewModel 实例.
The reason why this.$set
is not a function in your example code is because this
doesn't refer to Vue ViewModel instance anymore.
要使您发布的代码正常工作,您需要保留对它的引用:
To make code you've posted working, you need to keep reference to it:
export default {
data: function() {
return { movies: '' }
},
ready: function() {
this.showMovies()
},
methods: {
showMovies: function() {
var vm = this; // Keep reference to viewmodel object
this.$http.get(config.api.url + '/movies').then(function (response) {
vm.$set('movies', response.data)
})
}
}
}
这篇关于类型错误:this.$set 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文