vue.js - 在去抖之前模拟加载旋转器

标签 vue.js vuejs2 lodash es6-promise debouncing

有谁知道如何在该方法中的反跳之前执行 this.isLoading = true ?

它应该是一个加载旋转器,当通过 axios 进行异步调用时,它将被动画化。

    methods: {
        searchAdminUsers: _.debounce(function(query) {
            this.isLoading = true       
            axios.get('api/searchEmployees?format=json', { params: { q:query } })
            .then(response => {
                let data = response.data.map(item => (
                    { text: `${item.FIRSTNAME} ${item.LASTNAME} - ${item.POSITION}`, id: item.ID }
                ))
                this.options = data
                this.isLoading = false
          })
          .catch(error => {
            console.log(error)
          })
        }, 250)
    }

最佳答案

创建另一个方法来更改 this.isLoading,并调用 debounces 方法。

methods: {
    wrapSearchAdminUsers(query) {
      this.isLoading = true

      this.searchAdminUsers(query)
    }

    searchAdminUsers: _.debounce(function(query) {
        axios.get('api/searchEmployees?format=json', { params: { q:query } })
        .then(response => {
            let data = response.data.map(item => (
                { text: `${item.FIRSTNAME} ${item.LASTNAME} - ${item.POSITION}`, id: item.ID }
            ))
            this.options = data
            this.isLoading = false
      })
      .catch(error => {
        console.log(error)
      })
    }, 250)
}

关于vue.js - 在去抖之前模拟加载旋转器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46725110/

相关文章:

javascript - 如何使用 Lodash 在数字数组中按位置排序

javascript - 合并 Javascript 对象中的嵌套数组

vue.js - 自定义 vue2-editor 工具栏

vue.js - 努克斯 : how to have css global styles in files rather than inside of a style tag

javascript - javascript 嵌套过滤器函数

javascript - vue-router 重定向不适用于路由推送

vue.js - 如何捕获 Vue.js 中自定义指令的点击事件?

vue.js - VueJS : Textarea input binding

javascript - Vue 中的 Immer 数据未更新

underscore.js - 将 mixin() 函数与 lodash 和 JSONSelect 结合使用