VUE CLI3.0安装及配置

# 安装
npm install -g @vue/cli

# 查看已安装版本
vue --version 或者 vue -V # 卸载 npm uninstall @vue/cli -g # 新建项目 vue create my-project # 项目启动 npm run serve # 打包 npm run build

在项目根目录新建文件  vue.config.js 
module.exports = {
    devServer: {
      port: 8080,                                                                                  // 端口号
      host: "localhost",
      https: false,                                                                          // https:{type:Boolean}
      open: true,                                                                           //配置自动启动浏览器
      // proxy: 'http://localhost:4000'                                          // 配置跨域处理,只有一个代理
      proxy: {
        "/api": {
          target: "<url>",                                                              //接口地址
          ws: true,                                                                       //是否代理websockets
          changeOrigin: true                                                            // 设置同源  默认false,是否需要改变原始主机头为目标URL
        },
        "/foo": {
          target: "<other_url>"
        }
      }                                                                                 // 配置多个代理
      
    },
    lintOnSave: false                                                       // 关闭eslint代码检查
  };
在引用的时候 直接 用‘/api’  代替路径

猜你喜欢

转载自www.cnblogs.com/xzybk/p/11590353.html