2

Here is the link

https://codepen.io/anon/pen/pqKrzY

html looks like

<span>items[selected].text: {{ items[selected].text }}</span>

and created:

created() {
  setTimeout(() => {
     this.items[0] = {
        text: "XX"
     };
     this.items[1] = {
        text: "YY"
     };
  }, 1000)
 }

this does not update automatically, if I click the select, it will change though. And if I remove setTimeout, it will update automatically.

2
  • try This: ` this.items[0].text = 'XX'; this.items[1].text = 'YY';` Commented Jan 8, 2019 at 6:35
  • It is working fine for me Commented Jan 8, 2019 at 6:41

2 Answers 2

1

You can't manipulate array in this way with vue please refer to: Common Gotchas

Here is an example how it would work: https://codepen.io/anon/pen/NezvYV

this.items.$set(0, {
            text: "XX"
         })
Sign up to request clarification or add additional context in comments.

1 Comment

Well you can read it all in the docs(vuejs.org/v2/guide/reactivity.html#Change-Detection-Caveats). $set is an alias for Vue.set
0

You can use

   this.items[0].text = 'XX';
   this.items[1].text = 'YY';

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.