diff --git a/README.md b/README.md index 58729f1..cea2ad6 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,8 @@ export default { **Escape:** Hide the list. ## States +**error:** Indicates if an error what thrown and what it was when fetching data. + **loading:** Indicates that awaits the data. **isEmpty:** Indicates that the input is empty. diff --git a/dist/vue-typeahead.common.js b/dist/vue-typeahead.common.js index a76e199..42c82f1 100644 --- a/dist/vue-typeahead.common.js +++ b/dist/vue-typeahead.common.js @@ -23,6 +23,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de exports.default = { data: function data() { return { + error: null, items: [], query: '', current: -1, @@ -59,6 +60,7 @@ exports.default = { return; } + this.error = null; this.loading = true; this.fetch().then(function (response) { @@ -73,6 +75,8 @@ exports.default = { _this.down(); } } + }).catch(function (err) { + _this.error = err; }); }, fetch: function fetch() { @@ -99,6 +103,7 @@ exports.default = { }, cancel: function cancel() {}, reset: function reset() { + this.error = null; this.items = []; this.query = ''; this.loading = false; diff --git a/src/main.js b/src/main.js index 461ea69..b6ec8f3 100644 --- a/src/main.js +++ b/src/main.js @@ -3,6 +3,7 @@ import { util } from 'vue' export default { data () { return { + error: null, items: [], query: '', current: -1, @@ -38,9 +39,10 @@ export default { return } + this.error = null this.loading = true - this.fetch().then((response) => { + this.fetch().then(response => { if (response && this.query) { let data = response.data data = this.prepareResponseData ? this.prepareResponseData(data) : data @@ -52,6 +54,8 @@ export default { this.down() } } + }).catch(err => { + this.error = err }) }, @@ -83,6 +87,7 @@ export default { }, reset () { + this.error = null this.items = [] this.query = '' this.loading = false