Vue本地将开启HTTPS

配置vue.config.js

  // 配置反向代理
  devServer: {
    proxy: {
      '/api': {
        target: 'https://172.31.120.61:8080/',
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    },
    // 开启https 访问时使用https://172.31.120.61:8081 
    // https://localhost:8081 也可以访问,不过自带info请求会报错 不清楚具体原因
    https: true
  }

运行npm run dev

 DONE  Compiled successfully in 4644ms                                                                                                                上午9:40:28


  App running at:
  - Local:   https://localhost:8081/
  - Network: https://172.31.120.61:8081/

  Note that the development build is not optimized.
  To create a production build, run npm run build.

此时便以https启动

看看效果吧

Vue本地将开启HTTPS_第1张图片
HTTPS效果.png

你可能感兴趣的:(Vue本地将开启HTTPS)