【发布时间】:2023-03-30 08:40:01
【问题描述】:
我是 Vue 新手,我不经常使用 Bootstrap,所以请原谅我的新手问题,我正在尝试创建一个 Vue 工具提示组件,我已经创建了一个以使用 css 来表现我想要的方式,但是,我遇到了一些可访问性问题,所以我决定改用 BootstrapVue 工具提示,但我不知道如何使用 Bootstrap 创建这个组件。 这基本上是我使用 css 的 Tooltip.vue 组件:
<template>
<div :class="`tooltip ${position}`">
<slot></slot>
<span class="tooltip-text">{{content}}</span>
</div>
</template>
<script>
export default {
name: 'Tooltip',
props: {
position: String,
content: String,
}
};
</script>
<style lang="scss">
.tooltip {
.......
</style>
然后我像这样在其他地方导入和使用我的组件:
<tooltip position="right" content="Right tooltip">Hover me</tooltip>
我创建了一个 TooltipBootstrap.vue 组件,希望具有相同的结构但使用 Bootstrap,但我不知道会怎样,这是我开始的:
-
我 npm 安装了 bootstrap-vue
<template> <div> <button v-b-tooltip.hover.${position}="'${content}'"></button> </div> </template> <script> import VBTooltip from 'bootstrap-vue'; export default { name: 'TooltipBootstrat', components: { VBTooltip, }, props: { position: String, content: String, } }; </script>
我正在阅读引导文档:https://bootstrap-vue.org/docs/directives/tooltip,但我不知道我是否按照它应该使用的方式使用它,所以我有点迷茫,不胜感激任何帮助/建议,谢谢!
【问题讨论】:
标签: vue.js vue-component bootstrap-vue