[Vuejs]-I want to know about vue asynchronous update

1πŸ‘

βœ…

In your example code you never call the updateMessage() function.

new Vue({
  el: "#app",
  data: {
    msg: ''
  },
  methods: {
    message: function() {},
    updateMessage: function() {
      const path = 'https://jsonplaceholder.typicode.com/posts/1';
      axios.get(path)
        .then((res) => {
          this.msg = res.data.title;
        })
        .catch((error) => {
          // eslint-disable-next-line
          console.error(error);
        });
    },
  },
  created() {
    this.message();
    this.updateMessage();
    this.$nextTick();
    this.$forceUpdate();
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <div>MSG: {{msg}}</div>
</div>
πŸ‘€muka.gergely

Leave a comment