You need to tell blade not to parse the data in your curly braces. You can do this by prefixing them with an @. For example:
<tr v-for="user in users">
<td><a href="/profile/@{{ user.slug }}">@{{ user.name }}</a></td>
</tr>
Hi,
I'm using vue.js in combination with blade.
(So I do not use vue-router)
What is the best way to link in a foreach loop with a slug?
This is not working:
<tr v-for="user in users">
<td><a href="/profile/{{ user.slug }}">{{ user. name }}</td>
</tr>
If you want to use data from your vue data you have to bind href like this:
<tr v-for="user in users">
<td><a :href="'/profile/' + user.slug">{{ user.name }}</a></td>
</tr>
Note that in your first example there was a space between user. and name 'user._name'. Also you didn't close the a-tag.
Don't use href attribute on a tr, it's not designed for this. If you really want to make a whole tr clickable, add an event listener to it.
<tr v-for="user in users" @click="userProfile(user)">
<td>{{ user.name }}</td>
</tr>
and then create a method for your vue instance / export
methods: {
userProfile(user){
window.location.href = '/profile/' + user.slug;
}
}
Please or to participate in this conversation.