I have emmited data from a component and I want to pass this data in data() function.
Here's what I mean
export default {
name: "App",
data() {
return {
newlist
};
},
components: {
InputForms,
List
},
methods: {
handler(obj) {
obj = this.newlist;
}
}
};
I want obj inside my handler method to be inside data(). Right now,this code is not compiling saying that newlist is not defined
newlistto be reactive you have to initialize it with a value other thanundefined.data: () => ({ newlist: null })will make it reactive. If you're using any of its properties inside the template, initiate it as an empty object:data: () => ({ newlist: {}}). Also, your method is wrong (you inverted the left and right sides of the assignment. It should be:methods: { handler(obj) { this.newlist = obj; }}. (I'm assuming you want to assign the value ofobjtothis.newlist, not the other way around).