我有一个小代码,可以在 Chrome、Opera、Edge 和 Firefox 上正常运行。但它在 Safari 上不起作用。
我是 Windows 用户,所以我不太熟悉 Safari,以便找出问题所在。
我使用这个网站作为参考,但我不确定它是否已更新,或者我是否可能误解了某些内容。但我想它应该可以工作。
https://caniuse.com/?search=javascript%20modules
我正在使用apache和php
我有 3 个文件(index.php > index.js > Entities/Contato.js)
尽力让它尽可能简单,但如果您需要其他任何东西,请告诉我。
谢谢
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
</head>
<body>
<!-- This one works just fine -->
<script>
console.log('init');
</script>
<!-- This one does not work -->
<script type="module" src="./js/index.js"></script>
</body>
</html>
index.js
import {
ContatoEntity,
} from './Entities/Contato.js';
$(document).ready(()=>{
Main.ContatoCreate();
})
class Main {
static ContatoCreate(){
let contatoCreate = new ContatoEntity();
console.log(contatoCreate.getContatoId());
}
}
Contato.js
class ContatoEntity{
constructor(form) {
this.form = form;
}
#contatoId='123';
#contatoNome;
#telefones = [];
getContatoId(){
return this.#contatoId;
}
}
export {
ContatoEntity,
}
再次感谢。我正在尝试不同的方法,当我更改代码时,我发现了第一个错误,当我搜索此错误时,我发现这两个链接可以解释正在发生的情况。事实是 Safari Windows 的最后一次发布是在 2010 年 Safari:语法错误:使用保留字“class”
(葡萄牙语 - 但不是关于 versinos 之类的解释) https://support.apple.com/pt-br/102665
再次感谢,现在要更改它以解决