VueCLI5.X版本构建项目(打包)本地打开报错

报错截图:
在这里插入图片描述
报错分析:

跨源请求只支持协议方案:http, data, chrome, chrome-extension, chrome-untrusted, https。

解决方案:

1、把项目部署到服务器
2、在vscode安装插件Live Server

在这里插入图片描述
在html文件右键打开:
在这里插入图片描述

其他:在vue-cli5之前的版本中,打包项目是可以本地打开的,只要在vue.config.js 中配置 publicPath 选项,但是在vue-cli5中无效。查看了打包文件后,发现vue-cli5打包的index.html中使用了 ES Module
在这里插入图片描述

<!doctype html>
<html lang="">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0">
  <link rel="icon" href="favicon.ico">
  <title>construct-zp</title>
  <script defer="defer" type="module" src="static/js/chunk-vendors.be7cdae2.js"></script>
  <script defer="defer" type="module" src="static/js/app.1d00b639.js"></script>
  <link href="static/css/chunk-vendors.3dcf1cd1.css" rel="stylesheet">
  <link href="static/css/app.9e5a03a7.css" rel="stylesheet">
  <script defer="defer" src="static/js/chunk-vendors-legacy.e1baa594.js" nomodule></script>
  <script defer="defer" src="static/js/app-legacy.b9d309ea.js" nomodule></script>
</head>

<body><noscript><strong>We're sorry but construct-zp doesn't work properly without JavaScript enabled. Please enable it
      to continue.</strong></noscript>
  <div id="app"></div>
</body>

</html>

就是 type="module" 的两个script导致的问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值