0

I have a async function, which adds an attribute to one of my vue data objects. When I use this data object in my template I can't use the added attribute in the async function. Is there a way to reload the data as soon as the new attribute is added?

Here is an example of my problem:

<template>
  <div>
    {{object.attribute}}
    {{object.newAttribute}}
  </div>
</template>

<script>
export default {
  data: function() {
    return {
      object: {attribute: 'foo'},
    }
  }
  created: function() {
    this.createNewAttribute();
  },

  methods: {
    createNewAttribute: function() {
    setTimeout(function() {
      this.object['newAttribute'] = 'boo';
    }, 9000);
    }
  }
}
</script>

In this example only the first attribute 'foo' is rendered. How can I update the template as soon as the seconds attribute is ready?

2
  • this.$set(this.object, 'newAttribute', 'boo') Commented Nov 5, 2018 at 18:42
  • Vue can't detect when a property is added to an object. See the accepted answer in the linked duplicate post for a full explanation. Commented Nov 5, 2018 at 18:46

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.