vue-admin-template删除(替换)mock数据

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;
    }

大功告成!
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值