this is undefined; where are you trying to use it, in the script or in the template?
Apr 16, 2021
7
Level 1
TypeError: Cannot read property '$emit' of undefined
I want to call to a method in my parent component within my child component.
so I used an event for that. but I can emit the event using,
this.$emit('event')
it shows an error in the console saying,
TypeError: Cannot read property '$emit' of undefined
how do I fix this?
Level 104
Seems you need to pass the context into the setup function:
https://v3.vuejs.org/guide/composition-api-setup.html#context
setup(props, context) {
// ...
User.register(newUser).then((data) => {
console.log(data);
if (data.data.user) {
context.emit('event');
// ...
1 like
Please or to participate in this conversation.