0

Having a bit of an issue adding data to HREF in Vue. I currently have the following code to render the respective icons.

           <v-card-text>
            <v-btn
              v-for="icon in icons"
              :key="icon"
              class="mx-3 white--text"
              icon
            >
              <v-icon  size="24px">{{ icon.icon }}
              </v-icon>
                <a :href="`#${icon.link}`" ></a>
            </v-btn>
          </v-card-text>

And the data as follows:

     icons: [
      {icon:'fab fa-facebook', link:'https://www.facebook.com/user'},
      {icon:'fab fa-twitter', link:'https://twitter.com/user'},
      {icon:'fab fa-linkedin', link:'https://www.linkedin.com/in/user/'},
      {icon:'fab fa-instagram', link:'https://www.instagram.com/user/'},
    ],

The icons themselves are rendering properly, but I can't for the life of me get the links to work.

How would I link up the href to the icon using {{icon.link}}

2
  • Maybe this Question will help you. Try to use the v-bind:. For example <a v-bind:href="'/icon/'+ i.id"> Commented Nov 5, 2018 at 11:41
  • 1
    :href="icon.link" ... This will bind the href but your link has no content Commented Nov 5, 2018 at 11:57

3 Answers 3

4

To bind the data you just have to do a v-bind in href, and correctly target the positioning you want inside the href, continue with the example that I will provide.

<div id="app">
<a :href="icons[1].link" >test</a>
</div>

new Vue({
el: '#app',
data: () => ({
icons: [
      {icon:'fab fa-facebook', link:'https://www.facebook.com/user'},
      {icon:'fab fa-twitter', link:'https://twitter.com/user'},
      {icon:'fab fa-linkedin', link:'https://www.linkedin.com/in/user/'},
      {icon:'fab fa-instagram', link:'https://www.instagram.com/user/'},
    ]
})
})

Example: https://jsfiddle.net/hamiltongabriel/ke8w9czy/16/

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

Comments

2

You don't have any content inside of the <a>-tag. This should work:

<v-card-text>
  <v-btn
    v-for="icon in icons"
    :key="icon"
    class="mx-3 white--text"
    icon
  >
    <a :href="`#${icon.link}`">
      <v-icon size="24px">{{ icon.icon }}</v-icon>
    </a>
  </v-btn>
</v-card-text>

Comments

0

You could assign the href property directly to the vuetify button.

<v-btn
    v-for="icon in icons"
    :key="icon"
    class="mx-3 white--text"
    icon
    :href="icon.link"
    >
    <v-icon  size="24px">{{ icon.icon }}
    </v-icon>
</v-btn>

Vuetify Button Doc

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.