Vue开发配置

设置代理:

新建vue.config.js

module.exports = {
    // 关闭eslint
    lintOnSave: false,
    devServer: {
        proxy: { //配置跨域
            '/api': {
                target: 'https://www.wanandroid.com', //这里后台的地址模拟的;应该填写你们真实的后台接口
                changOrigin: true, //允许跨域
                pathRewrite: {
                    /* 重写路径,当我们在浏览器中看到请求的地址为:http://localhost:8080/api/core/getData/userInfo 时
                      实际上访问的地址是:http://121.121.67.254:8185/core/getData/userInfo,因为重写了 /api
                     */
                    '^/api': ''
                }
            }
        }
    }
}

 

 

 

运行项目后自动浏览器打开配置:

在packages.json 文件中
   "scripts": {
        "serve": "vue-cli-service serve --open",
        "build": "vue-cli-service build"
    }

serve 添加 --open

 关闭eslint:

在项目根目录下新建vue.config.js文件
module.exports = {
// 关闭eslint
lintOnSave:false
}

 为src设置别名,避免../../../src 的出现:

在项目根路径新建jsconfig.json文件

// 设置别名
{
  "compilerOptions": {
    "baseUrl": "./",
    "paths": {
      "@/*": [
        "src/*"
      ]
    }
  },
  "exclude": [
    "node_modules",
    "dist"
  ]
}

 

posted @ 2022-01-26 14:41  疯子FK  阅读(79)  评论(0编辑  收藏  举报