vue-resource-mock-up
v0.0.4
Published
Simple mock up plugin for project used Vue Resource
Downloads
13
Readme
vue-resource-mock-up
Simple mockup plugin for Vue Resource
Installation
npm install --save-dev vue-resource-mock-up
or
yarn add -D vue-resource-mock-up
Usage
Just register this plugin in your main file (entry point file). That's it!
import VueResource from 'vue-resource'
import Mocking from 'vue-resource-mock-up'
import routes from './routes' // All mock up APIs will be place in routes
...
Vue.use(VueResource) // This line of code must be placed on top
Vue.use(Mocking, routes)
Example of routes
export default [{
method: 'get',
url: '/api/users',
response: function (request) {
return [{
userId: 1,
name: 'User 1'
},
{
userId: 2,
name: 'User 2'
}
]
}
},
{
method: 'post',
url: '/api/user',
delay: 5000, // Delay 5 seconds before returning data. Default: 2 seconds
response: function (request) {
return {
success: true,
message: 'ok'
}
}
},
{
method: 'put',
url: '/api/user',
response: function (request) {
return null
}
}
]
API Response
API reponse will depend on your route return
- 200: if you return an object
- 500: if you return null
- 404: if there is no matching route