项目目录结构
3.请求处理
3.1使用mockjs模拟后端API
index.js ##mock配置文件
mock-server.js ##mock本地服务配置
table.js
user.js ##用户的后端API响应数据
utils.js3.2模拟后端接口
module.exports = [
// user login
{
url: "/vue-admin-template/user/login",
type: "post",
response: config => {
const { username } = config.body; //获取req.body.username
const token = tokens[username]; //获取用户的tookens
// mock error
if (!token) {
return {
code: 60204,
message: "Account and password are incorrect."
};
}
return {
code: 20000,
data: token //验证成功,返回token数据
};
}
}]3.3axios发起ajax请求
4.前端路由跳转
5.组件使用封装好的API
6.Vuex用于组件间的通信
参考
Last updated