v0.6.22

區塊插入

最後更新


本頁說明如何以 <temp :path> 載入外部 HTML 檔並插入模板。

寫法


  1. <div id="app">
  2. <temp :path="/components/header.html"></temp>
  3. <temp :path="footerUrl"></temp>
  4. </div>
  5. <script>
  6. const app = new QUI({
  7. id: "app",
  8. data: { title: "QuickUI", footerUrl: "/components/footer.html" },
  9. });
  10. </script>
即時預覽 · @pardnchiu/quickui@0.6.22

header.html 的內容會取代 <temp> 元素本身;插入的內容一樣可以使用 {{ }}、:for、:if 與其他指令。

規則


規則說明
標籤只有 <temp> 上的 :path 有效
路徑先當資料鍵查找,找不到時直接當 URL
載入時機每次渲染都會重新 fetch;快取交給瀏覽器 HTTP 快取
處理順序在 :for、:if 之後載入,載入後對插入內容再跑一次 :for 與 :if
執行環境必須透過 HTTP 伺服器;file:// 下 fetch 會失敗

錯誤情況


情況結果
回應為 404 等錯誤狀態不檢查狀態碼,錯誤頁的內容會被插入
網路錯誤或 CORS 拒絕fetch 拋出例外,該次渲染中止,畫面停在上一次的結果

部署時請確認每個 :path 都指向存在的檔案。
EN