admin管理员组文章数量:1323716
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:''},
{icon:'fab fa-twitter', link:''},
{icon:'fab fa-linkedin', link:'/'},
{icon:'fab fa-instagram', link:'/'},
],
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}}
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./user'},
{icon:'fab fa-twitter', link:'https://twitter./user'},
{icon:'fab fa-linkedin', link:'https://www.linkedin./in/user/'},
{icon:'fab fa-instagram', link:'https://www.instagram./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}}
Share Improve this question asked Nov 5, 2018 at 11:36 Mtlj1991Mtlj1991 1972 gold badges5 silver badges13 bronze badges 2-
Maybe this Question will help you. Try to use the
v-bind:
. For example<a v-bind:href="'/icon/'+ i.id">
– xFuture Commented Nov 5, 2018 at 11:41 -
1
:href="icon.link"
... This will bind thehref
but your link has no content – Dan Commented Nov 5, 2018 at 11:57
3 Answers
Reset to default 4To 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./user'},
{icon:'fab fa-twitter', link:'https://twitter./user'},
{icon:'fab fa-linkedin', link:'https://www.linkedin./in/user/'},
{icon:'fab fa-instagram', link:'https://www.instagram./user/'},
]
})
})
Example: https://jsfiddle/hamiltongabriel/ke8w9czy/16/
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>
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
本文标签: javascriptAdding data to href in VUEStack Overflow
版权声明:本文标题:javascript - Adding data to href in VUE - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742125705a2421929.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论