简体   繁体   English

[Vue 警告]:无法解析指令:b-popover

[英][Vue warn]: Failed to resolve directive: b-popover

<template>
  <div>
    <div class="text-center my-3">
      <b-button
        v-b-popover.hover="'I am popover content!'"
        title="Popover Title"
        >Hover Me</b-button
      >
    </div>
  </div>
</template>

<script>
import { VBPopover } from "bootstrap-vue";
export default{
  directives: {
    VBPopover
  },
}
<script>

So I am not sure why I am getting this warning.所以我不确定为什么我会收到这个警告。 If I replace vb-popover.hover with b-popover.hover this warning goes away but the functionality is not there.如果我用 b-popover.hover 替换 vb-popover.hover 这个警告消失但功能不存在。

Basically trying to implement the popover directive from the docs: https://bootstrap-vue.org/docs/directives/popover基本上试图从文档中实现popover指令: https://bootstrap-vue.org/docs/directives/popover

Directive IDs are automatically prefixed with v- .指令 ID 自动以v-为前缀。 You should probably explicitly set the directive ID as indicated here您可能应该明确设置指令 ID,如此处所示

directives: {
  'b-popover': VBPopover
}

What was happening is that发生的事情是

directives: {
  VBPopover 
}

is the same as是相同的

directives: {
  VBPopover: VBPopover
}

and the name VBPopover was transformed to vb-popover and then had the automatic prefix applied to become vvb-popover .并且名称VBPopover被转换为vb-popover ,然后应用自动前缀成为vvb-popover So you could use that in your template but to me, it looks pretty silly.所以你可以在你的模板中使用它,但对我来说,它看起来很傻。

Directives don't behave like components when it comes to their names.当涉及到它们的名称时,指令的行为不像组件。 Directive names are always transformed to kebab-case and prefix with v- .指令名称始终转换为kebab-case并以v-为前缀。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM