Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error handling cabability on fetch #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions dist/vue-typeahead.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -59,6 +60,7 @@ exports.default = {
return;
}

this.error = null;
this.loading = true;

this.fetch().then(function (response) {
Expand All @@ -73,6 +75,8 @@ exports.default = {
_this.down();
}
}
}).catch(function (err) {
_this.error = err;
});
},
fetch: function fetch() {
Expand All @@ -99,6 +103,7 @@ exports.default = {
},
cancel: function cancel() {},
reset: function reset() {
this.error = null;
this.items = [];
this.query = '';
this.loading = false;
Expand Down
7 changes: 6 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { util } from 'vue'
export default {
data () {
return {
error: null,
items: [],
query: '',
current: -1,
Expand Down Expand Up @@ -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
Expand All @@ -52,6 +54,8 @@ export default {
this.down()
}
}
}).catch(err => {
this.error = err
})
},

Expand Down Expand Up @@ -83,6 +87,7 @@ export default {
},

reset () {
this.error = null
this.items = []
this.query = ''
this.loading = false
Expand Down