P
P
pasha_carol2019-06-20 16:34:01
JavaScript
pasha_carol, 2019-06-20 16:34:01

How to refer to an object within an object in Vue?

Hello, please help me understand.
I need to write the text that is typed in textareato an object that lies inside another object.

An object:

data(){
    return {
      sections: [
        {
          name: 'My Question',
          active: true,
          messages: [
            {text: 'Hello, what is dilivery time?'},
            {text: 'Hello, what is dilivery?'}
          ],
        },
        { name: 'Messanger', active: false },
        { name: 'Community QA', active: false },
        { name: 'FAQ', active: false }
      ],
    }
  },


I need to add a key : valuemessages to another element .
My attempt:

methods: {
    addMsg: function (msg) {
      this.sections.messages.push({text: msg})
      return false;
    }
  }


this.sections.messagesproduces undefined.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2019-06-20
@pasha_carol

Well, this.sections is your array, you need to access this.sections[0].messages.push({text: msg}) by index

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question