Vue.js (2.x) with Bootstrap 5(带Bootstrap 5的Vue.js(2.x))
本文介绍了带Bootstrap 5的Vue.js(2.x)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将Bootstrap 5与Vue(2.x)一起使用,而不使用任何第三方库。我的想法是为我想要使用的每个Bootstrap组件(不是全部)创建一个包装器。
我使用以下so线程作为基础:Using Bootstrap 5 with Vue 3
我创建的第一个组件是bootstrap.Alert。到目前为止,它运行得无懈可击。
<template>
<div ref="el" class="alert alert-danger alert-dismissible fade show" role="alert">
<div>{{ message }}</div>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
</template>
<script>
import { Alert } from 'bootstrap';
export default {
name: 'BootstrapAlert',
props: {
message: {
type: String,
default: '',
},
},
created() {
Alert(this.$refs.el);
},
mounted() {
const { el } = this.$refs;
[
'close',
'closed',
].forEach((e) => {
el.addEventListener(`${e}.bs.alert`, () => {
this.$emit(e);
});
});
},
};
</script>
第二个是bootstrap.Toast,这有点问题:
<template>
<div ref="el" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<strong class="me-auto">Bootstrap</strong>
<small class="text-muted">just now</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">See? Just like this.</div>
</div>
</template>
<script>
import { Toast } from 'bootstrap';
export default {
name: 'BootstrapToast',
created() {
Toast(this.$refs.el);
},
};
</script>
尽管植入/代码几乎相同,但在呈现Toast组件时总是出现以下错误:
[Vue warn]:创建的钩子中出错:TypeError:无法读取属性 未定义的‘_getConfig’
如果我尝试在已装载事件中移动Toast启动,而不是已创建,则收到不同的错误:
[Vue warn]:装载的钩子中出错:TypeError:无法设置属性 未定义&q;的‘_Element’
有人知道哪里出了问题吗?
提前谢谢!
=工作解决方案=
<script>
import { Toast } from 'bootstrap';
export default {
name: 'BootstrapToast',
data() {
return {
toast: null,
};
},
mounted() {
this.toast = new Toast(this.$refs.el);
this.toast.show();
},
};
</script>
Toast
您需要使用new Toast(..)
启动推荐答案,并确保它位于已挂载的()钩子中...
mounted() {
var toast = new Toast(this.$refs.el)
toast.show()
},
Codeply
这篇关于带Bootstrap 5的Vue.js(2.x)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:带Bootstrap 5的Vue.js(2.x)
猜你喜欢
- Fetch API 如何获取响应体? 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Flexslider 箭头未正确显示 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01