1

I tried backticks + signs, everything and I can't parse the HTML in my data object to the template.

Check the screenshot for the issue.

<script>
export default {
  name: 'Navigation',
  data() {
    return {
     paths: [
      {
        id: 1,
        title: ' +  <b-icon icon="house"></b-icon> +',
        url: '/'
      },
      {
        id: 2,
        title: 'Binding',
        url: 'binding'
      },
    }
  }
}
<script>

enter image description here

6
  • This is a bad idea to proceed like that IMO but here you go: vuejs.org/api/built-in-directives.html#v-html Commented Oct 21, 2022 at 10:33
  • A dynamic component is probably better than trying to eval some HTML: vuejs.org/guide/built-ins/keep-alive.html#basic-usage Commented Oct 21, 2022 at 10:34
  • Otherwise, you can also use this kind of solution if you want any kind of icons: stackoverflow.com/a/72055404/8816585 It's written for Nuxt but works for pretty much anything really. Commented Oct 21, 2022 at 10:35
  • Yeah its not just specific for icons, but how to pass html.. but thanks :) Commented Oct 21, 2022 at 10:48
  • We don't have the whole template of your code here but usually, it's a bad idea to pass directly some HTML. Especially if you can make so that it's still handled by Vue and not completely out of control by a random string. Render functions are also a thing, making that more strict: vuejs.org/guide/extras/… Commented Oct 21, 2022 at 10:50

1 Answer 1

1

OP solved the issue by using the following

<nav>
  <router-link v-for="path in paths" :to="path.url">
    <span>
      <b-icon 
        icon="house" 
        v-if="path.url === '/'"
      ></b-icon>
      {{ path.title }}
    </span>
  </router-link>
</nav>
Sign up to request clarification or add additional context in comments.

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.