簡體   English   中英

如何在 typescript vue js 項目中將 html 文件作為模板導入為模塊,以便在多個組件中使用相同的 html 文件?

[英]How to import html file as template in typescript vue js project as module to use same html file in more than a component?

我正在嘗試將外部 html 文件加載到 typescript 語言的 Vuejs 項目中,但 typescript 編譯器給我的問題如下

ERROR  Failed to compile with 1 errors                                                                                                    3:51:57 PM
 error  in ./src/components/common/dynamic-render.html

我沒有 webpack.config.js 因為這個項目是通過 vue-cli 生成的

我試圖在vue-template-loader ts-loader的幫助下加載文件,但編譯器仍然拋出同樣的問題

儀表板.vue

import WithRender from "./common/dynamic-render.html";

@WithRender
@Component

我得到以下錯誤

ERROR  Failed to compile with 1 errors                                                                                                    3:51:57 PM
 error  in ./src/components/common/dynamic-render.html

Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

您是否按照本文中的說明定義了shims-html.d.ts

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM