npm安装anywhere( 随启随用的静态文件服务器),分分钟解决浏览器请求本地js文件跨域问题

以下是一个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...

相关推荐
Lsx-codeShare6 小时前
前端发版后页面白屏?一套解决用户停留旧页面问题的完整方案
前端·javascript·前端框架·vue·vite
心柠6 小时前
TypeScript的知识梳理
前端·javascript·typescript
Cache技术分享6 小时前
354. Java IO API - 获取路径信息
前端·后端
北寻北爱6 小时前
面试篇-vue中第三方库的使用(echarts)
前端
luanma1509806 小时前
Spring 框架——@Retryable 注解与 @Recover 注解
java·前端·spring
llxxyy卢6 小时前
polar-web部分中等题目
android·前端·sql·web安全
非凡ghost6 小时前
Zen Browser:基于 Firefox 的极简开源浏览器,隐私与速度兼得
前端·网络·windows·学习·开源·firefox·软件需求
ivwsjc7 小时前
vue3 echarts地图点到点之间的飞线图
前端·javascript·vue·echarts
小李子呢02117 小时前
JS中的Set 核心认知
前端·javascript·es6
程序员阿耶7 小时前
【前端面试知识点】CSS contain 属性如何用于性能优化?它有哪些可选值及作用?
前端·面试