2017-03-15 21 views
2

我試圖去運行一個函數500ms運行。在此之後的文檔:VueJS 2未捕獲的ReferenceError:_沒有用去抖動定義

https://vuejs.org/v2/guide/migration.html#debounce-Param-Attribute-for-v-model-removed

methods: { 
     // Get the data needed for this page 
     fetchData: _.debounce(function() { 
      this.$http.get('widgets/quickfindordernumber/' + this.quickFindOrderNumber).then(function (response) { 
       console.log(response.body) 
      }, function (error) { 
       console.log(error); 
      }); 
     }, 500) 
    } 

但運行此功能時,我在控制檯Uncaught ReferenceError: _ is not defined得到一個錯誤,我曾試圖消除_。在反彈前,但它表示反彈也沒有定義。

+2

_是下劃線或lodash,外部庫,不Vue公司。 – Bert

回答

3

在此示例中,VueJS使用來自外部庫(如underscoreJS或lodash)的debounce函數。

與它的作品,你只包括這在你的文件(後您的NPM模塊來安裝這個)是這樣的:

include _ from 'lodash'; 

new Vue({ 
    // ... 
    methods: { 
     // Get the data needed for this page 
     fetchData: _.debounce(function() { 
      this.$http.get('widgets/quickfindordernumber/' + this.quickFindOrderNumber).then(function (response) { 
       console.log(response.body) 
      }, function (error) { 
       console.log(error); 
      }); 
     }, 500) 
    } 
}); 
相關問題