2017-03-15 11 views
2

私は500msの間実行している機能をデバウンスしようとしています。ここでは、次のドキュメント:VueJS 2 Uncaught 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でエラーが発生します。 debounceの前にありますが、debounceも定義されていません。

+2

_アンダースコアまたはlodash、外部ライブラリではなく、Vueのです。 – Bert

答えて

3

この例では、VueJSはアンダースコアやロダッシュのような外部ライブラリの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) 
    } 
}); 
関連する問題