javascript - 如何在 VueJS 2 中使用 Bootstrap 5 折叠组件?
问题描述
我正在尝试在按钮上使用 Bootstrap 5 的“折叠”组件,但我不确定如何在 VueJS2 中实际使用它
我有一个像这样的文件组件:
<template>
部分:
<button
class="btn btn-danger"
type="button"
data-bs-toggle="collapse"
data-bs-target="#collapseExample"
aria-expanded="false"
aria-controls="collapseExample"
>
Mark As Rejected
</button>
<div class="collapse" id="collapseExample">
<div class="card card-body">
Some placeholder content for the collapse component. This panel is
hidden by default but revealed when the user activates the
relevant trigger.
</div>
</div>
<script>
部分:
<script>
import Collapse from 'bootstrap/js/dist/collapse'
export default {
...
methods: {
// how to manually enable the collapse via JavaScript???
}
}
...
</script>
Bootstrap 文档有一个使用 vanilla JavaScript 的示例……但是如何使用 VueJS 呢?
Bootstrap 5 折叠原生 JavaScript 示例:
var collapseElementList = [].slice.call(document.querySelectorAll('.collapse'))
var collapseList = collapseElementList.map(function (collapseEl) {
return new bootstrap.Collapse(collapseEl)
})
解决方案
我只是想多了。
为了在带有 HTML 数据属性的 VueJS 单文件组件中使用 Collapse,我所要做的就是简单地导入 Collapse 文件,如下所示:
import 'bootstrap/js/dist/collapse'
这也将允许轻松摇树,因为我只需要在需要时导入脚本。
推荐阅读
- nlp - 根据含义比较文本
- html - 如何突出显示/悬停/单击 HTML 表格中选定的一组连续行单元格
- c# - Nuget PackageReferences 未将 dll 复制到 bin 目录
- python - 在 AWS EC2 中安装 Jupyter
- javascript - 复选框 html 没有更新我的变量状态用户脚本?
- sql-server - 如何使用内存中的 SQL Server 进行集成测试?
- cmake - add_custom_target 并不总是重新运行
- haskell - If 语句使用 IO Int haskell
- c# - 右键单击部署时如何运行--publish-local-settings?
- r - dplyr: case_when() over multiple columns with multiple conditions