2017-10-13 38 views
1

누구든지이 메서드에서 디 바운딩 전에 this.isLoading = true를 어떻게 실행할 수 있는지 알고 있습니까?디 바운스 전에 로딩 스피너 시뮬레이션

액시즈를 통해 비동기 호출을 할 때 애니메이션으로 로딩되는 로딩 스피너가 있어야합니다.

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) 
}