I am quite new to Vue.js, and for some reason the child to parent emit is not working.
Basically, I have Search component within a Box component. On my Search component, I tried doing:
@Watch("searchValue", { immediate: true })
onSearch(value: string, oldValue: string) {
console.log(this.searchValue); // this is logged OK
this.$emit("search-val-change", this.searchValue);
}
Then on the box component template:
<box @search-val-change="doSearch">
<search></search>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</box>
On the box.ts file:
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
@Component
export default class Box extends Vue {
doSearch() {
console.log("TEST EMIT"); // nothing is console logged, means it doesn't come to this part at all
}
}
I am getting this error:
[Vue warn]: Property or method "doSearch" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
...although it is defined as a method. I am using the Vue Class Decorator which states that I can define methods directly.
Anything wrong with the syntax / flow?
box.tsfile the same location of the<box @search-val-change="doSearch">bit of code? - Tony