[Vuejs]-Rest API doesn't load data quick enough before the route is shown using vue.js and vue-router

1👍

Use vue-router’s data hook.

http://router.vuejs.org/en/pipeline/data.html

route: {
  data: function (transition) {
    return this.$http.get(...);
  }
}

Then, in the template:

<div v-if="$loadingRouteData">Loading ...</div>
<div v-else>Your current HTML.</div>

1👍

A simple fix is to prevent Vue from trying to access the object property:.
First set the initial content value to null, based on your example, there is no reason to set is as an empty array. Looks like it will get assigned an object from your response data. Then, in your view, just do this:

{{{ content ? content.content.rendered : null }}}

Leave a comment