admin管理员组文章数量:1289528
This is the HTML.
<navlink v-bind:href="#about">About</navlink>
And the main.js code is
Vueponent('navlink', {
template: '<li class="item"><a><slot></slot></a></li>'
});
But I'm getting error
[Vue warn]: failed to pile template: - invalid expression: v-bind:href="#about"
How to fix this?
This is the HTML.
<navlink v-bind:href="#about">About</navlink>
And the main.js code is
Vue.ponent('navlink', {
template: '<li class="item"><a><slot></slot></a></li>'
});
But I'm getting error
[Vue warn]: failed to pile template: - invalid expression: v-bind:href="#about"
How to fix this?
Share Improve this question edited Dec 28, 2016 at 12:09 craig_h 32.7k7 gold badges61 silver badges70 bronze badges asked Dec 28, 2016 at 7:41 anoop chandrananoop chandran 1,5005 gold badges25 silver badges44 bronze badges 4- I dont see any error here. Have to included all relevant code. – Saurabh Commented Dec 28, 2016 at 7:47
- @anoopchandran I am not sure at all if i intended this. very sorry for this mistake – Muhammad Omar ElShourbagy Commented Dec 28, 2016 at 8:09
- @Muhammad Omar ElShourbagy .. Its Okay..Thank you – anoop chandran Commented Dec 28, 2016 at 8:11
- @saurabh.. I tried your code.. it doesnt work. – anoop chandran Commented Dec 28, 2016 at 8:24
3 Answers
Reset to default 8I realise that you have solved this, but v-bind
expects you to be pointing to an object in your parent class's data
and you are trying to use a string literal, so Vue throws an error because it cannot find an object with that key.
You may also prefer to pass href
as a prop to your ponent instead, so you end up with:
Vue.ponent('navlink', {
template: '<li class="item"><a :href="href"><slot></slot></a></li>',
props: ['href']
});
and then you can just do:
<navlink href="#about">About</navlink>
Here's the JSFiddle: https://jsfiddle/ov94tg5z/
Try to add more quotes)
<navlink v-bind:href="'#about'">About</navlink>
Okay I managed to fix it.. like this.. HTML
<navlink href="#about">About</navlink>
And JS
Vue.ponent('navlink', {
template: '<a class="item"><slot></slot></a>'
});
本文标签: javascriptHow to pass href value to template in VueStack Overflow
版权声明:本文标题:javascript - How to pass href value to template in Vue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741401023a2376667.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论