4

I have a list group whose list items are rendered from an API call. For example,

  {
    "MenuID": "1",
    "Name": "<span v-b-tooltip.hover title=\"Self Help Training\">Help</span>",
    "Url": "example.com"
  }

I have the below HTML,

  <ul class="list-group list-group-flush">
    <li class="list-group-item list-group-item-action" v-for="(link, i) in links" :key="i">
      <a :href="link.Url" v-html="link.Name"></a>
    </li>
  </ul>

The tooltip does not work when hovered on the item. Can you please help me understand why that is and how it can be fixed? Thanks

3
  • the name property is just html text and render with v-html directive, in this way, vue will not compile the content Commented May 18, 2018 at 8:29
  • 3
    you can register a component with template <span v-b-tooltip.hover title="Self Help Training">Help</span>,and use props to receive the tooltip text and title text Commented May 18, 2018 at 8:31
  • Does this answer your question? How can add bootstrap tooltip inside Vue.js Commented Mar 3, 2020 at 12:54

4 Answers 4

0

When using a dynamic block, you need dynamic ids. That means that you have to have different id for every link you have and to make sure you use the same id when create the target for your tooltip. Personally, I create a dynamic id if the item does not already have one.

<div>
  <p>{{itemName}}</p>
  <div>
    <img :id="'prod_' + prodId" src="../assets/utility/product.svg">
  </div>
  <b-tooltip :target="'prod_' + prodId" triggers="hover">
    Delete item from the list!
  </b-tooltip>
</div>
Sign up to request clarification or add additional context in comments.

Comments

0

It's quite late for the answer, but maybe somebody would find it useful.

API response:

  {
    "MenuID": "1",
    "Name": "Help",
    "Title": "Self Help Training",
    "Url": "example.com"
  }

Then modify your HTML this way:

  <ul class="list-group list-group-flush">
    <li
      class="list-group-item list-group-item-action"
      v-for="(link, i) in links"
      :key="i"
    >
      <a :href="link.Url">
        <span v-b-tooltip.hover :title="link.Title">
          {{ link.Name }}
        </span>
      </a>
    </li>
  </ul>

Comments

-1

Old post but I do not see v-tooltip in your code.

  <ul class="list-group list-group-flush">
    <li class="list-group-item list-group-item-action" v-for="(link, i) in links" :key="i">
      <a :href="link.Url" v-html="link.Name"></a>
    </li>
  </ul>

Do something like this

  <ul class="list-group list-group-flush">
    <li class="list-group-item list-group-item-action" v-for="(link, i) in links" :key="i">
      <a :href="link.Url" v-tooltip="'Your Tooltip message'" v-html="link.Name"></a>
    </li>
  </ul>

3 Comments

The tooltip is within the html of the API call. Issue is that this vue doesn't interprets the directives in injected html.
Ok I see it as v-b-tooltip. It most likely has to becase the way your code is written. "<span v-b-tooltip.hover title=\"Self Help Training\">Help</span>". Looks like you are trying to pass a string on key Name. You are escaping the string before Self Help Training. Can you try "<span v-b-tooltip.hover title='Self Help Training'>Help</span>". Also, I got mine working yesterday by doing v-tooltip.hove :title= and not v-b-tooltop. Hope this helps.
- The issue stays the same. The "<span ...>" is something fetched by the API, not something in the code. - The "v-b-tooltip" is a bootstrap tooltip. - The comment of @jacky is the best approach. The API should not give html, just a 'tooltip text' and a 'content text'. And then you use those properties in a component.
-2

based https://bootstrap-vue.js.org/docs/components/tooltip/ you must add v-b-tooltip directive.

<ul class="list-group list-group-flush">
  <li class="list-group-item list-group-item-action" v-for="(link, i) in links" :key="i">
     <a :href="link.Url" v-html="link.Name" v-b-tooltip.hover :title="link.Name"></a>
  </li>
</ul>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.