以下是一个html文件, chrome浏览器打开该文件;
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=600, initial-scale=1.0">
<title>Vite App</title>
<script type="module" crossorigin src="/assets/index-GxicIufr.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-U9LxSyeS.css">
</head>
<body>
<div id="app"></div>
</body>
</html>
报错如下:
js
Access to script at 'file:///Users/***/Documents/code/learning/vue/vue-project/dist/assets/index-GxicIufr.js'
from origin 'null' has been blocked by CORS policy:
Cross origin requests are only supported for protocol schemes:
http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.
index.html:8
Access to CSS stylesheet at 'file:///Users/shuangguiyu/Documents/code/learning/vue/vue-project/dist/assets/index-U9LxSyeS.css'
from origin 'null' has been blocked by CORS policy:
Cross origin requests are only supported for protocol schemes:
http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.
index.html
全局安装anywhere npm install -g anywhere
,再前往html文件所在目录执行anywhere -p 8081
Anywhere 随启随用的静态文件服务器。 www.npmjs.com/package/any...