vue框架中实现mock数据模拟后端接口-提高开发效率
1,npm安装mockjs
npm install mock.js
2,src目录下新建mock文件夹-新建index.js
import Mock from 'mockjs';
const userInfo = Mock.mock(
'/test.advance/login','post', (req, res) =>{
return {
code:200,
data:{
userId:1,
userName:'zpc',
token: 'jgfldkgjkl'
},
message:'登录成功'
}
} )
export default { userInfo }
3.在main.js引入,index.js文件
4,.在组件中登录的时候直接调用