vue.js - 将 Bootstrap 与 VueJS 一起使用时未捕获的 TypeError
问题描述
我正在尝试将引导程序与我的 vue 项目集成,但是当我打开浏览器时,我的控制台会出现以下错误。
config.js?228e:8 Uncaught TypeError: Cannot read property 'prototype' of undefined
at eval (config.js?228e:8)
at Module../node_modules/bootstrap-vue/esm/utils/config.js (chunk-vendors.js:3262)
at __webpack_require__ (app.js:854)
at fn (app.js:151)
at eval (alert.js?5fda:1)
at Module../node_modules/bootstrap-vue/esm/components/alert/alert.js (chunk-vendors.js:94)
at __webpack_require__ (app.js:854)
at fn (app.js:151)
at eval (index.js?cca8:1)
at Module../node_modules/bootstrap-vue/esm/components/alert/index.js (chunk-vendors.js:106)
我跑了$ vue add bootstrap-vue
,它创造了bootstrap-vue.js
import Vue from 'vue'
import BootstrapVue from 'bootstrap-vue'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
Vue.use(BootstrapVue)
Vue 版本:3
引导版本:4
有关如何修复此错误或在 vue 上安装引导程序的任何建议?谢谢
解决方案
根据这个Github 问题和他们的Vue-Bootstrap 文档,目前无法将 Vue3.x 与 Bootstrap 一起使用,因为存在一些重大的重大变化。
问题中提到了这一点:
请注意,Vue 2.x 和 Vue 3.x 之间有很多重大变化,这需要在 BootstrapVue 中进行更改。
被广泛使用的 Vue.extend 在 Vue 3.x 中不可用。(替换为 Vue 3.x 导出的 createComponent() 方法)
你可以先导入 Vue 和 createComponent,然后设置 Vue.export = createComponent,然后导入第三方库(如 PortalVue、BootstrapVue 等)。
推荐阅读
- json - 用双引号(“)括起来的字符串会导致 json.loads() 出错
- c# - 如何在 c# xUnit 测试用例中模拟构造函数?
- java - 如何注册自定义约束验证器
- python - 文件更新上的 Office365-REST-Python-Client 401
- flutter - Flutter 无法正确使用文本字段
- c# - 如何检查在单元测试期间是否修改了静态变量
- angular - 角慢加载初始页面
- php - Laravel 多对多关系返回空数组
- django - 使用 Jinja / Django 显示 Algolia 结果
- php - 我的buddypress自定义标签代码有什么问题?