我是打字稿和 vue 3 js 的新手。我寫了一個單檔案組件,并想使用 Bootstrap 5 模式。但是我的 VSCode 在我宣告的變數型別上顯示錯誤。錯誤說:
“模態”是指一個值,但在這里用作一種型別。您的意思是“模態型別”嗎?
<script setup lang="ts">
import { Modal } from "bootstrap";
let modal: Modal = null;
...
</script>
我通過 npm bootstrap 和 bootstrap 中的所有 JS 型別安裝
npm install --save-dev @types/bootstrap
有人有想法嗎?
uj5u.com熱心網友回復:
你缺typeof運營商嗎?
<script setup lang="ts">
...
let modal: typeof Modal = null;
...
</script>
uj5u.com熱心網友回復:
僅匯入模式的型別
import type { Modal } from "bootstrap";
uj5u.com熱心網友回復:
Negin Khademian 的回答為我指明了正確的方向。我從引導程式進行了第二種型別的匯入,并使用別名來避免沖突。現在看起來像這樣:
<script setup lang="ts">
import type { Modal } from "bootstrap";
import { Modal as BootstrapModal } from "bootstrap";
let modal: Modal | null = null;
...
modal = new BootstrapModal( document.getElementById( 'myModal' ) );
...
</script>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/521068.html
標籤:打字稿Vue.js引导程序 5
