vue2 配置运行环境

vue2 配置运行环境

在 vue2 项目中配置运行环境

  • 在项目中新建 .env.development 文件 和 .env.production 文件
    在这里插入图片描述
  • .env.development
NODE_ENV = 'development'
//指定当前环境模式
VUE_APP_MODE = 'development'
VUE_APP_BASE_URL = "/dev-api"
  • .env.production
NODE_ENV = "production"
//指定当前环境模式
VUE_APP_MODE = 'production'
VUE_APP_BASE_URL = "http://"  // 线上地址
  • 配置 vue.config.js 文件
module.exports = {
  publicPath: process.env.NODE_ENV === "production" ? "./" : "/",
  outputDir: "dist",
  assetsDir: "static",
  devServer: {
    proxy: {
      [process.env.VUE_APP_BASE_URL]: {
        target: 'http://',  // 本地后台地址
        changeOrigin: true,
        pathRewrite: {
        [`^${process.env.VUE_APP_BASE_URL}`]: ''
        }
      }
    },
  },
  transpileDependencies: true,
  lintOnSave: false,
}
  • request/index.js 中添加 baseURL
import axios from "axios"

const request = axios.create({
  baseURL: process.env.VUE_APP_BASE_URL,
  timeout: 10000,
  headers: {
    "Content-Type": "application/x-www-form-urlencoded;charset=utf8",
  },
  responseType: "json",
})

相关推荐

最近更新

  1. TCP协议是安全的吗?

    2024-05-16 11:54:16       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-16 11:54:16       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-16 11:54:16       20 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-16 11:54:16       20 阅读

热门阅读

  1. vue3 遇到的那些问题呀

    2024-05-16 11:54:16       12 阅读
  2. flutter 嵌套 StatefulWidget 不刷新

    2024-05-16 11:54:16       11 阅读
  3. logstach+elasticsearch+kibana整合后台.log文件

    2024-05-16 11:54:16       10 阅读
  4. 解密 Unix 中的 “rc“ 后缀:自定义你的工作环境

    2024-05-16 11:54:16       10 阅读
  5. oracle 临时表 在sql 里面用完要删除吗

    2024-05-16 11:54:16       11 阅读
  6. 简单上手SpringBean的整个装配过程

    2024-05-16 11:54:16       13 阅读
  7. Oracle 数据块之变化时的SCN

    2024-05-16 11:54:16       12 阅读