I'm creating a test Component in Vue.js. I want to pass a parameter to use in my template as follows:
Vue.component('test', {
props: ['href'],
template: '<li><a href="{{href}}"><slot></slot></a></li>'
});
In my html file:
<test href="/">Tvest</test>
But the property href
is not binding to the attribute.
<li><a href="{{href}}">Tvest</a></li>
How can I do it properly in Vue.js?
Use the v-bind directive to set the prop:
<a v-bind:href="href"><slot></slot></a>
or shortcut
<a :href="href"><slot></slot></a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.