数据发送之前isLoading:true,发送完成之后isLoading:false
1.gif

1.仅一个页面使用

官网https://youzan.github.io/vant/#/zh-CN/loading#jia-zai-lei-xing

1.在main.js中引入Loading

  1. import { Loading } from 'vant';
  2. Vue.use(Loading);

2.使用

  1. <van-loading type="spinner" color="#1989fa" />
  1. <template>
  2. <div class="about">
  3. <Load v-if="isLoading"></Load> //加载条 ,使用了全局组件Load
  4. <p>{{ title }}</p>
  5. <img :src="pic" alt="" />
  6. </div>
  7. </template>
  8. <script>
  9. export default {
  10. name: "About",
  11. data() {
  12. return {
  13. title: "",
  14. pic: "",
  15. isLoading: false
  16. };
  17. },
  18. mounted() {
  19. this.isLoading=true; //发送请求之前
  20. var url = "https://douban-api.uieee.com/v2/movie/subject/30221757";
  21. this.axios.get(url).then(res => {
  22. this.title = res.data.title;
  23. this.pic = res.data.images.small;
  24. this.isLoading=false; //发送请求之后
  25. });
  26. }
  27. };
  28. </script>
  29. <style scoped>
  30. </style>
  1. //components/Load.vue
  2. <div>
  3. <van-loading type="spinner" color="#1989fa" />
  4. </div>

2.使用vuex,并写入全局组件中

  1. //store/index.js
  2. export default new Vuex.Store({
  3. state:{
  4. isLoading:true
  5. },
  6. })

直接写在全局组件中,只要页面发送请求都会触发
App.vue

  1. <div id="app">
  2. <van-loading v-if="this.$store.state.isLoading"
  3. size="24px" type="spinner" color="#1989fa">加载中...</van-loading>
  4. </div>