vue-admin-template是一个相对比较完善的脚手架前端项目,登录后的主界面如下
想要去掉moke,需要做一下几步,
1.修改.env.development,将base api修改为本地的
# just a flag
ENV = 'development'
# base api
//VUE_APP_BASE_API = '/dev-api'
VUE_APP_BASE_API = 'http://127.0.0.1'
2.修改main.js,注释掉以下代码
/**
* If you don't want to use mock-server
* you want to use MockJs for mock api
* you can execute: mockXHR()
*
* Currently MockJs will be used in the production environment,
* please remove it before going online ! ! !
*/
// if (process.env.NODE_ENV === 'production') {
// const { mockXHR } = require('../mock')
// mockXHR()
// }
3.修改request.js,注释以下代码
// create an axios instance
const service = axios.create({
//baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
// withCredentials: true, // send cookies when cross-domain requests
timeout: 5000 // request timeout
})
4.修改vue.config.js,注释掉moke行代码
// All configuration item explanations can be find in https://cli.vuejs.org/config/
module.exports = {
/**
* You will need to set publicPath if you plan to deploy your site under a sub path,
* for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
* then publicPath should be set to "/bar/".
* In most cases please use '/' !!!
* Detail: https://cli.vuejs.org/config/#publicpath
*/
publicPath: '/',
outputDir: 'dist',
assetsDir: 'static',
lintOnSave: process.env.NODE_ENV === 'development',
productionSourceMap: false,
devServer: {
port: port,
open: false,
overlay: {
warnings: false,
errors: true
},
//before: require('./mock/mock-server.js'),
后台的话,可以自己模拟数据返回,只要格式合理就行
/**
* 用户登录
* @param params
* @return
*/
@RequestMapping(value = "/login", method = {RequestMethod.POST })
public Map login(@RequestBody Map params) {
// return userService.login(params);
HashMap<String, Object> response = new HashMap<>();
HashMap<String, Object> responseData = new HashMap<>();
responseData.put("token","admin-token");
response.put("code",200);
response.put("msg","登录成功");
response.put("data",responseData);
return response;
}
@GetMapping("/info")
public Map info(@RequestParam(value = "token") String token) {
HashMap<String, Object> response = new HashMap<>();
return response;
}
大功告成!