- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试导入 redom库,但不断收到此错误:
未捕获的 TypeError:无法读取 null 的属性“nodeType”
我的代码如下:
<!DOCTYPE html>
<html>
<head>
<script src='test.js'></script>
<script src="libraries/redom.min.js" type='text/javascript'></script>
<script>
const { el, mount } = redom;
const hello = el('h1', 'Hello World');
mount(document.body, hello);
</script>
</head>
<body>
</body>
</html>
如果我将 const { el, mount } = redom;
更改为 import { el, mount } from 'redom'
,我会得到 Uncaught SyntaxError: Unexpected token 导入
。
路径正确,redom.min.js没有坏。
最佳答案
向加载 redom
的脚本添加属性 type="module"
可能会解决问题(如果您使用最新的 Chrome):
<script src="libraries/redom.min.js" type="module"></script>
然而,由于大多数浏览器不支持 import
语句,因此预计会有异常,请参阅引述:
Note: This feature is not implemented in any browsers natively at this time. It is implemented in many transpilers, such as the Traceur Compiler, Babel, Rollup or Webpack.
Source: import - JavaScript | MDN
关于javascript - 无法从 redom 库导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47002638/
我正在尝试导入 redom库,但不断收到此错误: 未捕获的 TypeError:无法读取 null 的属性“nodeType” 我的代码如下: cons
我有 DOM elementA 、 elementB 和 elementC 。ElementA 是父级,我想在其中添加 elementB 和 elementC。 我尝试过使用 setChildren,
我是一名优秀的程序员,十分优秀!