我想实施以下流程:

当http请求正在进行时,显示加载程序.当请求完成时,隐藏加载程序.

推荐答案

我假设您希望在http请求进行时显示加载程序.

<template>

    <div>

        <div v-if="loading">
            <!-- here put a spinner or whatever you want to indicate that a request is in progress -->
        </div>

        <div v-else>
            <!-- request finished -->
        </div>

    </div>

</template>

<script>
    import axios from 'axios'

    export default {
        data: () => {
          loading: false
        },

        methods: {
          makeRequest () {
            this.loading = true //the loading begin
            axios.get('/example')
            .then(response => { ... }) // code to run on success
            .catch(error => { ... }) // code to run on error
            .finally(() => (this.loading = false)) // set loading to false when request finish
          }
        }
    }
</script>

Note that I am using 100 in the example, but the logic works with other htpp libraries or 101

Vue.js相关问答推荐

vue3中的转换可以在滑入但不能滑出时工作

更新 Shopware 管理 CMS 组件中的编辑器视图

视图中的 vue 样式不适用于 html

使用内部方法创建计算(computed)属性是否合法?

Vue-tables-2(vuex)react性不起作用

VuetifyJS:如何摆脱 v-stepper 组件的提升?

是否可以在没有 Vue 的情况下使用 Vuex?

一个 div 组件中的 Vue.js 2.0 路由链接

如何使用 laravel-mix 将 bootstrap-vue 加载到 Laravel 5 中?

vue-router的router-link实际刷新?

JavaScript/VueJS:判断数组是否包含具有特定值元素的对象

Vuejs:我应该在 vue-router SPA 中的哪里放置一些常用的 js 工具?

Vue 组件中的组件渲染函数中可能存在无限更新循环警告

在路由更改之前显示确认对话框

Vue Js如何在单个文件模板中使用mixins?

嵌套组件

vue-router如何持久化导航栏?

Vuetify 离线文档

使用 CloudFront 部署在 S3 上的 VueJS 应用程序的指定的密钥不存在

将它们分开时将 Django 的 csrf_token 放入 Vuejs