Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

href tag breaks vue template component

I am trying to add a href link with a variable in my vue template, for some reason it keeps breaking and I have no clue why, it’s trying to reference it as a variable rather than a link. the issue is with the "/post/update" href. the "/view-user/ + post.user.id" works fine

<template>
<div id="content">
    <div class="post">
        <h3>{{post.title}}</h3>
        <p>{{post.content}}</p>
        <a :href="/view-user/ + post.user.id">
            {{post.user.username}}
        </a>
        <p>{{ post.created_at.split(".")[0] }}</p>
        <a :href="/post/update/ + post.id">Edit</a>
    </div>
    <hr>
    <comment :id="id"/>
</div>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The static part of the href value should be wrapped by '' as string :

 <a :href="'/view-user/' + post.user.id">

or string template :

 <a :href="`/view-user/${post.user.id}`">

in your case it’s evaluated as expression.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading