这个应该是浏览器兼容问题,具体啥原因我也不懂,反正解决了
- 首先先安装一下 npm install @vitejs/plugin-legacy
- 再去vite.config.ts配置一下
import legacy from '@vitejs/plugin-legacy';
build: {
target: 'es2015',
},
plugins:[
legacy({
targets: ['Chrome 69'],
additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
modernPolyfills: true,
}),
]
4.最后在index.html 添加globalThis声明就可以了,虽然是vue但这里直接使用this就行,不要纠结,先解决问题
<script type="module" src="/src/main.ts">
this.globalThis || (this.globalThis = this)
</script>