【发布时间】:2021-10-30 09:38:25
【问题描述】:
我正在尝试在按钮上使用 Bootstrap 5 的 "collapse" component,但我不确定如何在 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>
使用原生 JavaScript 的 Bootstrap docs had an example...但是如何使用 VueJS 来做到这一点?
Bootstrap 5 折叠原生 JavaScript 示例:
var collapseElementList = [].slice.call(document.querySelectorAll('.collapse'))
var collapseList = collapseElementList.map(function (collapseEl) {
return new bootstrap.Collapse(collapseEl)
})
【问题讨论】:
标签: javascript vuejs2 bootstrap-5