htmx 1.x → htmx 2.x 遷移指南

本指南旨在提供從 htmx 1.x 遷移到 htmx 2.x 的說明。我們非常重視向後兼容性,因此在大多數情況下,此遷移應該只需要很少甚至不需要任何工作。

若要使用新方法進行交換,您只需使用

let content = "<div>Hello world</div>"; // this is HTML that will be swapped into target
let target = api.getTarget(child);
let swapSpec = api.getSwapSpecification(child);
api.swap(target, content, swapSpec);

swap 方法文件可在 JS API 參考上找到

htmx 2.0 不再支援 IE,但 htmx 1.x 繼續支援 IE,並且在可預見的未來將會繼續支援。

#升級音樂

這是官方 htmx 1.x -> 2.x 升級音樂