javascript - 当 popover 指令起作用时,什么会导致 popover 组件失败
问题描述
我正在尝试使用 BootstrapVue 的弹出框。据我所知,我正在进口我需要的一切
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
crossorigin="anonymous">
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css"/>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap-vue@2.7.0/dist/bootstrap-vue.common.min.js"
integrity="sha256-NTImazhsLEaQ0a59ZMLLxaOfFnKZNLJbbTcZh9YBM58="
crossorigin="anonymous"></script>
我可以使用弹出框
<div id="general-info" class="questionMarkHelp" v-b-popover.hover.bottom="'På denna sida kan du se en sammanställning av statistik för din kommun'">
但是当我尝试使用 b-popover 时,它不起作用
<font-awesome-icon id="investigations" icon="question-circle" size="2x"/>
<b-popover target="investigations" placement="bottom" triggers="hover">
Här kan du statistik över utredningar.<br>
Du kan se hur många utredningar din kommun har.<br>
Hur många som är pågående.<br>
Hur många som ledde till insats.<br>
Hur många som inte ledde till insats
</b-popover>
如您所见,我希望能够使用
标签格式化弹出框内的文本。否则我可能只会满足于使用指令类型。
解决方案
如果您正在使用Bootstrap-Vue
,则不需要导入jQuery
,popper
和bootstrap.js
. 您可以在此处阅读需要导入的内容。
您唯一需要从引导程序导入的是它们的 CSS/SCSS。(您仍然可以导入jQuery
,popper
如果您将它们用于其他用途,但这不是必需的)
我由 Vue 特定组件处理的所有其他内容Bootstrap-Vue
。
您的代码可以正常工作,如果我不导入不必要的文件,您可以在下面的代码段中看到。(我已经用 Bootstrap-Vue 图标组件替换了你的 font-awesome-icon,这应该没什么区别)。
另一件需要注意的是,该v-b-popover
指令支持html
修饰符将您传入的字符串格式化为 HTML。
编辑:
看起来bootstrap-vue.common.min.js
不支持该b-popover
组件,将其切换为导入bootstrap-vue.min.js
而不是修复该组件。
new Vue({
el: "#app",
data() {
return {
text: "Här kan du statistik över utredningar.<br>Du kan se hur många utredningar din kommun har.<br>Hur många som är pågående.<br>Hur många som ledde till insats.<br>Hur många som inte ledde till insats"
}
}
});
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
crossorigin="anonymous">
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@2.7.0/dist/bootstrap-vue.css"/>
<!-- Import Vue and Bootstrap-Vue Javascript-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap-vue@2.7.0/dist/bootstrap-vue.min.js"></script>
<!-- Only imported for this example -->
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue-icons.min.js"></script>
<div id="app" class="container">
<!-- Using the directive with the HTML modifier -->
<b-icon v-b-popover.html.hover.bottom="text" icon="question"></b-icon>
<!-- Using the component -->
<b-icon id="investigations" icon="info"></b-icon>
<b-popover target="investigations" placement="bottom" triggers="hover">
<span v-html="text"></span>
</b-popover>
</div>
推荐阅读
- python - try 和 except 块以提高值错误
- reactjs - 使用会话存储在移动应用程序中每天显示一次模式
- python - 特定不和谐频道的 OnMessage 例程
- typescript - TypeScript 中是否可以使用泛型基于另一个参数的类型来约束回调参数?
- python - 在 pyspark 数据框中的单元格中将 CSV 值分隔为新列及其值
- javascript - 404 Not Found for index.html in Google App Engine - 如何让页面显示?
- reactjs - 在另一个 div 中渲染 React 组件
- django - 用postgres在一行中处理多个布尔项目?
- git - 有没有办法撤消`git reset --hard HEAD~1`?
- python - 如何在 python 中执行与字符串具有相同“文本”的变量