vue add mockjs-server
Modify vue.config.js
:
pluginOptions: {
mockjs: {
path: path.join(__dirname, './mock'),
debug: true,
port: 3000
}
}
- create
json
file inmock
folder - create
js
file inmock
folder
/**
* Show favourite user @url /user/love
*/
{
"code": 0,
"result|5": [
{
"id|+1": 1,
"name": "@name",
"email": "@email"
}
]
}
/**
* User Login @url /user/login
*/
module.exports = () => {
return {
code: '200',
data: {
userName: '@cname()',
// Token值
tokenValue: '@guid()',
}
- Visit http://localhost:3000 to see the mock dashboard
- Visit http://localhost:3000/user/love to see the mocked JSON result
- Visit http://localhost:3000/user/login to see the mocked JSON result
Most of the codes are from @soon08.