Hi I am geting this error: Uncaught (in promise) TypeError: this.$set is not a function
And here is the code:
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)
})
}
}
}
The TypeError: "x" is not a function can be fixed using the following suggestions: Paying attention to detail in code and minimizing typos. Importing the correct and relevant script libraries used in code. Making sure the called property of an object is actually a function.
This is a standard JavaScript error when trying to call a function before it is defined. This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the expression did not return a function object.
The TypeError object represents an error when an operation could not be performed, typically (but not exclusively) when a value is not of the expected type. A TypeError may be thrown when: an operand or argument passed to a function is incompatible with the type expected by that operator or function; or.
In short, the "is not a function" error means that the value you're trying to invoke is not a function. The most common reasons this error occurs are: defining a variable with the same name that shadows the original object. calling a method on a value of a different type, e.g. calling the Array.
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)
})
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With