2

I would like a popover to display one or multiple hyperlinks when clicked on. I am able to get other Bootstrap elements to interpret HTML by using the v-html argument although it is not working in this case.

Here's my code:

<template>
  <div>
    <b-button
      :id="popover"
      size="sm"
    >
      Button
    </b-button>
    <b-popover
      :target="popover"
      triggers="focus"
      v-html="actions"
    >
      {{ actions }}
    </b-popover>
  </div>
</template>

<script>
  export default {
    computed: {
      actions() {
        return [
          `<a href="www.google.com">Google</a><br>`,
          `<a href="www.youtube.com">Youtube</a><br>`
        ].join('')
      }
    }
  }
</script>

1 Answer 1

3

Remove the binding sign : on target and id then change them to popover1 then create a nested div with v-html directive which has as value actions :

<template>
  <div>
    <b-button
      id="popover1"
      size="sm"
    >
      Button
    </b-button>
    <b-popover
      target="popover1"
      triggers="focus"
    
    >
    <div v-html="actions"></div>
    </b-popover>
  </div>
</template>

<script>
  export default {
    computed: {
      actions() {
        return [
          `<a href="www.google.com">Google</a><br>`,
          `<a href="www.youtube.com">Youtube</a><br>`
        ].join('')
      }
    }
  }
</script>

If the id and target attributes are bound to a property you should keep the binding sign.

Sign up to request clarification or add additional context in comments.

4 Comments

For the avoidance of doubt to later readers, you don't have to remove the dynamic binding on target and id to make this work. Its just it isn't appropriate in the OP. Putting the actions inside a div is the critical part.
thanks for your comment but i don't understand what do you mean
Its a very good answer that you gave. I just mean that you said to remove the bindings. Some people might think that you must remove those bindings to make v-html work.
Yeah you're right , some people could define the id and target values as data or computed property

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.