0

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

1
  • If you want newlist to be reactive you have to initialize it with a value other than undefined. 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 of obj to this.newlist, not the other way around). Commented Jul 18, 2020 at 21:55

1 Answer 1

1

Change newlist to newlist: {} then inside your method swap what you already have:

handler(obj) {
   this.newlist = obj;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.