[英]Vue & Typescript: Image imports not found
我目前正在使用Typescript進行Vue項目。 在我的Assets文件夾中,我有一些圖像想通過單獨的Typescript文件導入。
該項目由vue-cli使用Typescript版本3.2.1
引導。 我嘗試過的是使用require直接導入到我的文件中,該方法不起作用。 然后我試圖與進口import
無濟於事
這是我嘗試過的:
./src/myFile.ts
import Image from '@/assets/img/hello.png';
不起作用
./src/myFile.ts
import Image from '../assets/img/hello.png';
不起作用
./src/myFile.ts
const Image = require('../assets/img/hello.png');
不起作用
捆綁器將沿Relative modules were not found
的行引發錯誤,后跟文件路徑。 我已經確定路徑正確,並且我懷疑這與TypeScript如何管理導入以及Vue-cli如何配置為捆綁文件有關。
找到了問題:您需要像下面這樣聲明以下模塊:
declare module "*.png" {
const value: string;
export default value;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.