【问题标题】:Simulating a loading spinner before debounce在去抖动之前模拟加载微调器
【发布时间】:2018-03-25 07:21:09
【问题描述】:

有谁知道如何在此方法的去抖动之前执行 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)
    }

【问题讨论】:

    标签: vue.js vuejs2 lodash es6-promise debounce


    【解决方案1】:

    创建另一个更改 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)
    }
    

    【讨论】:

    • 欣赏奥日
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-19
    • 1970-01-01
    • 2020-06-29
    • 1970-01-01
    • 2019-01-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多