参考博客 https://blog.csdn.net/weixin_46058357/article/details/107545202
1、安装
npm install --save mockjs
2、使用
1)在src文件夹下创建mock文件夹
2)在mock文件夹中创建index.js文件和json文件
main.js
import '../mock/index.js'
json文件
{
"status":1,
"msg":"scu"1
}
index.js
//引入
const mockHttp = require('mockjs')
//模拟接口
mockHttp.mock('/login/loginPhone','get',require('./json/loginPhone.json'))
aip.js
export function loginPhone(data){
return new Promise((resolve,reject)=>{
axios({
method:'get',
url:'/login/loginPhone'
}).then((res)=>{
resolve(res.data);
}).catch((err)=>{
reject(err)
})
})
}