如何使用 BootstrapVue 工具提示创建 Vue 工具提示组件
How to create a Vue Tooltip component using BootstrapVue tooltip
我是 Vue 的新手,我不经常使用 Bootstrap 所以请原谅我的新手问题,我正在尝试创建一个 Vue 工具提示组件,我已经创建了一个行为方式我想使用 css,但是,我 运行 遇到了一些可访问性问题,所以我决定改用 BootstrapVue 工具提示,但我不知道如何创建它Bootstrap 的组件。
这基本上是我的 Tooltip.vue 组件使用 css:
<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>
我正在阅读 bootstrap 文档:https://bootstrap-vue.org/docs/directives/tooltip,但我不知道我是否按照预期的方式使用它,所以我有点迷茫并感谢任何 help/advice,谢谢!
BootstrapVue 提供 <b-tooltip>
组件和 v-b-tooltip
指令(document 中的首选方法)。您可以在文档中尝试一下。
简单来说,你可以在任何元素上使用v-b-tooltip
指令,非常方便。但对于 <b-tooltip>
组件,您必须设置 target
以识别激活工具提示的目标。
因此,在您的情况下,您可以执行以下操作:
<template>
<div v-b-tooltip="{ title: content, placement: position }">
<slot></slot>
</div>
</template>
<script>
import { VBTooltip } from 'bootstrap-vue'
export default {
name: 'Tooltip',
directives: {
'b-tooltip': VBTooltip,
},
props: {
position: String,
content: String,
}
};
</script>
我是 Vue 的新手,我不经常使用 Bootstrap 所以请原谅我的新手问题,我正在尝试创建一个 Vue 工具提示组件,我已经创建了一个行为方式我想使用 css,但是,我 运行 遇到了一些可访问性问题,所以我决定改用 BootstrapVue 工具提示,但我不知道如何创建它Bootstrap 的组件。 这基本上是我的 Tooltip.vue 组件使用 css:
<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>
我正在阅读 bootstrap 文档:https://bootstrap-vue.org/docs/directives/tooltip,但我不知道我是否按照预期的方式使用它,所以我有点迷茫并感谢任何 help/advice,谢谢!
BootstrapVue 提供 <b-tooltip>
组件和 v-b-tooltip
指令(document 中的首选方法)。您可以在文档中尝试一下。
简单来说,你可以在任何元素上使用v-b-tooltip
指令,非常方便。但对于 <b-tooltip>
组件,您必须设置 target
以识别激活工具提示的目标。
因此,在您的情况下,您可以执行以下操作:
<template>
<div v-b-tooltip="{ title: content, placement: position }">
<slot></slot>
</div>
</template>
<script>
import { VBTooltip } from 'bootstrap-vue'
export default {
name: 'Tooltip',
directives: {
'b-tooltip': VBTooltip,
},
props: {
position: String,
content: String,
}
};
</script>