Rendering after ajax request

时间:2017-12-18 07:28:45

标签: vue.js

I have order_detail objects that look like this:

place

They are retrieved from the backend and assigned to a "london" : { capital: true, images: ["pic1.jpg","pic2.jpg"], ... } object in place.

The issue/question I have is how to handle the delay in retrieving the data from the backend when rendering the view.

My template might have something like this:

data

but this causes errors/warnings in the console because there is no such thing as the images array until the data has been fetched.

I can think of two ways to handle this.

  1. I define an empty images array within the data object. But I would have to do this for every property (and sub-property) that I will potentially use which isn't ideal.
  2. I use <p>{{place.images[0]}}</p> and a v-if variable to conditionally render the template part.

Is there a "vuejs" approach to this that I've not considered?

1 个答案:

答案 0 :(得分:-1)

I think you are looking for The DateTime.TryParseExact directive

This directive will remain on the element until the associated Vue instance finishes compilation.

You have to use like

v-cloak

Read about v-cloak in docs, and more discussion