-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Phase 6 - Use v-model axios rest wrapper. Add error checking
1. `npm install v-model --save` or modify package.json per example and run npm install 2. added todoModel.js to replace the axios based todoRestApi from phase 5 3. modified main.js to use todoModel and the [vmodel](https://github.com/laoshu133/v-model) Model based methods 4. Add some error checking with `catch` and a div in index.html to diplay errors 5. Modify the Todo domain in grails so we can simulate an error by creaating an item with 'xxx'
- Loading branch information
Showing
6 changed files
with
69 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Model from 'v-model' | ||
import Promise from 'bluebird' | ||
|
||
// set baseURL and install plugin | ||
Model.http.defaults.baseURL = 'http://localhost:8080/api/'; | ||
|
||
const TodoModel = Model.extend('/todo/:id') | ||
|
||
TodoModel.updateAll = todos => { | ||
todos.forEach(function (todo) { | ||
todo.$update() | ||
}) | ||
} | ||
|
||
TodoModel.archiveCompleted = todos => { | ||
todos.filter(function (todo) { | ||
return todo.completed | ||
}).forEach(function (todo) { | ||
todo.$delete().then(response => { | ||
todos.splice(todos.indexOf(todo), 1) | ||
//console.log("deleted", todo) | ||
}) | ||
}) | ||
} | ||
|
||
TodoModel.errors = { message: '' } //set to data. | ||
|
||
// Add a response interceptor for default errors from Grails rest | ||
TodoModel.http.interceptors.response.use(function (response) { | ||
TodoModel.errors.message = '' | ||
return response | ||
}, function (error) { | ||
console.log("error.response ", error.response) | ||
TodoModel.errors.message = error.response.data.message | ||
return Promise.reject(error) | ||
}) | ||
|
||
export default TodoModel |