嗨,我試圖在帶有打字稿的 vue 3 應用程式中使用 bootstrapVue,這里是我的 main.ts:
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import Vue from 'vue'
import { BootstrapVue } from 'bootstrap-vue'
createApp(App).use(router).use(BootstrapVue).mount('#app')
導致此錯誤:
src/main.ts:9:32
TS2345: Argument of type 'BootstrapVuePlugin' is not assignable to parameter of type 'Plugin_2'.
Type 'BootstrapVuePlugin' is not assignable to type '{ install: PluginInstallFunction; }'.
Types of property 'install' are incompatible.
Type 'PluginFunction<BvConfigOptions>' is not assignable to type 'PluginInstallFunction'.
Types of parameters 'Vue' and 'app' are incompatible.
Type 'App<any>' is missing the following properties from type 'VueConstructor<Vue>': extend, nextTick, set, delete, and 3 more.
7 |
8 |
> 9 | createApp(App).use(router).use(BootstrapVue).mount('#app')
| ^^^^^^^^^^^^
10 |
有誰知道這個問題的解決方案?提前致謝。
uj5u.com熱心網友回復:
當前版本bootstrap-vue(v2.21.2) 僅支持 Vue 2,但有一個 GitHub 問題跟蹤 Vue 3 支持(bootstrap-vue問題 #5196)。
同時,還有一個支持 Vue 3 的第三方版本:
- 安裝
bootstrap和bootstrap-vue-3:
npm i -S bootstrap bootstrap-vue-3
- 初始化
bootstrap-vue-3中main.ts:
import { createApp } from 'vue'
import BootstrapVue3 from 'bootstrap-vue-3'
// Since every component imports their Bootstrap functionality,
// the following line is not necessary:
// import 'bootstrap'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue-3/dist/bootstrap-vue-3.css'
const app = createApp(App)
app.use(BootstrapVue3)
app.mount('#app')
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/368806.html
標籤:javascript 打字稿 Vue.js 进口 引导-vue
上一篇:Hibernatejava.util.ConcurrentModificationException中的迭代器錯誤問題:null
