data mock service for developer
npm install uni-mock -save-dev
uni-mock
touch a config file named um.config.js to set your own mock service
- path Set the listening directory according to the project
- suffix Set the service server path suffix
- host Set the service server host
- port Set the service server port
um.config.js
module.exports = {
path: "/mock",
suffix: "_MOCK_",
host: "localhost",
port: 8080
}
mock.json
{
"reponseCode": "0000",
"reponseData": {
"name": "Tom"
}
}
mock.js
module.exports = function (params){
if(params.name === 'Tom'){
return{
"reponseCode": "0000",
"reponseData": {
"name": "Tom"
}
}
}else{
return{
"reponseCode": "9999",
"reponseData": "invalid user name!"
}
}
}