前言:
因为很多项目必须要求是严格模式,不能有http请求,需要限制我们的请求头必须为https,如果是http的话,手动转成https来实现请求效果。
实现方法:
在 public/index.html 的 head 标签里面加入以下代码:
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
效果:
![](https://img-blog.csdnimg.cn/28b2cffe5eab4051b6f0237b645456ba.png)
源码:
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="renderer" content="webkit">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= webpackConfig.name %></title>
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>