Vue enters the page to display the question.

I now have such a problem:

<template>
    <div id="test">
       <div v-if="list.length">
           //
        </div>
       <div v-if="!list.length">
        //     
    </div>
    </div>
</template>

...
<script>
    ...
    data(){
        return {
            list:[]
        }
    }
</script>

description:

  • now the initial list assignment is an asynchronous behavior that occurs in mounted
  • and the above way of writing is to display the style without data by default. Once the data changes, the page flashes and the display data is replaced, which makes people feel very bad, because it is not that there is no data but that the data has not been passed. I hope that the entry page is empty instead of showing the style without data
  • here"s how I solved it. I added a vmuriff = "false" to-sharptest before assigning it to true, until the end of the initial asynchronous request, which ensures that what the page just came in didn"t look like a style without data
  • .

Q: how do you deal with this situation? do you feel superfluous? does vue provide a better solution or do you have a better solution?

add: in addition, the entrance to the page is a link in the navigation. As mentioned in @ tony_gong , pulling data before entering the route, if the back-end service is slightly weak, is it not more inappropriate for users to get the perception that the link does not respond?

Mar.21,2021

No. From a framework point of view, if even the design of empty data is included, it will undoubtedly add a variety of burdens and no benefits.

but for details, you can use v-if and v-else .


your idea is very close. You can add a third status to indicate that the data hasn't come yet. After getting the data, switch whether


this is a solution. In fact, there is another way to pull the data before entering the route


you can add a loading icon

Menu