2017-10-13 46 views
1

沒有人知道如何執行this.isLoading = true之前,在這種方法debounce?模擬負載微調前debounce

它應該是一個加載微調器,當通過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) 
    } 

回答

2

創建另一種方法,更改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) 
}