Vue Cli 3项目 ,配置代理、阻止webpack://源码泄露、新建+删除node_modules

根目录新建vue.config.js
vue.config.js

module.exports = {
  productionSourceMap: false, //防止源码泄露
  devServer: {
    proxy: {
        '/api': {
            target: 'http://test.xxx.com.cn', 
            ws: true,  // proxy websockets 
            changeOrigin: true,  // needed for virtual hosted sites
            pathRewrite: {
                '^/api': ''  // 设置过滤关键字api ,
           //   '^/': ''  // 设置过滤关键字为空 ,
            }
        },
    }
}
}

使用

//过滤字为api
axios.get("/api/login/login?openId=" + token)
      .then(function(response) {
        if (response.data) {
          //未登录
          if (response.data.code == 200) {
            //已登录
          } else {
            //no
          }
        }
      })
      .catch(function(error) {
        // Toast(error.data.msg);
      });

//过滤字为空
axios.get("/login/login?openId=" + token)
      .then(function(response) {
        if (response.data) {
          //未登录
          if (response.data.code == 200) {
            //已登录
          } else {
            //no
          }
        }
      })
      .catch(function(error) {
        // Toast(error.data.msg);
      });

新建项目Vue cli 3

 //安装 Vue Cli
npm install -g @vue/cli

 //创建一个项目
vue create hello-world

//打开图形化界面  好东西-直接安装:插件、依赖
vue ui

图形化界面如图
Vue Cli 3项目 ,配置代理、阻止webpack://源码泄露、新建+删除node_modules_第1张图片
删除node_modules

安装
npm install rimraf -g

使用
rimraf node_modules

你可能感兴趣的:(vue)