在 Firefox 中导入 JSON 时出现问题,但在其他浏览器中可以正常工作

问题描述 投票:0回答:1

在我的新项目中,我遇到了 Firefox 的问题。首先我想说的是,在 Opera、Chrome 和 Edge 中它运行良好,但只有在其中一种浏览器中才会出现意外错误。

我正在使用本地 JSON 和一些对象,然后在 JS 中我使用

// Import JSON Insurance Data

import insurances from './insurances.json' assert {type: 'json'}

然后

insurances.forEach(e => {myCode});

就像我所说的,它通常可以工作,但在 Firefox 的控制台中却出现错误:

SyntaxError: unexpected token: identifier

浏览器指向这一行:

import insurances from './insurances.json' assert {type: 'json'}
javascript json firefox
1个回答
2
投票

仅查看 MDN 文档,Firefox 不支持导入断言。

我也很困惑它为什么能在 Opera 中为你工作,因为目前它被列为不受支持,与 Firefox 一样。

在此处查看更多信息:MDN 导入浏览器兼容性

© www.soinside.com 2019 - 2024. All rights reserved.