我在一些动态生成的 DOM 元素上使用 HTMX 属性。如文档中所述,HTMX 不起作用,除非您调用htmx.process()
.
当我试图调用它时,我得到 - 正确 - 错误:
未捕获的 ReferenceError:未定义 htmx
知道如何导入这个 htmx 变量吗?不知道文档中的示例如何工作。
谢谢!
的非模块版本htmx.org
定义了一个全局,但您正在使用模块(通过import
)。模块的一半是取消全局变量,因此它的模块版本不会创建全局变量,它会返回导出。
在已删除的评论中,您说实际的导入是import "htmx.org"
(import htmx.org
与仍然存在的评论不同)。在这种情况下,您可能想要其中之一:
// Importing the default export
import htmx from "htmx.org";
// Or importing the module namespace object
import * as htmx from "htmx.org";
// Or importing a named export, but looking at the file I doubt you want this one
import { htmx } from "htmx.org";
最有可能的是,您想要第一个。
您可以在进行htmx.process()
呼叫的模块中执行此操作。