Javascript 如何在Vue.js中动态构建路由器链接?
我尝试在Vue.js中执行以下操作Javascript 如何在Vue.js中动态构建路由器链接?,javascript,vue.js,Javascript,Vue.js,我尝试在Vue.js中执行以下操作 <table> <tr v-for="item in messages"> <td><router-link to="'/user/' + item.id">{{ item.name }}</router-link></td> </tr> </table> {{item.name} My
<table>
<tr v-for="item in messages">
<td><router-link to="'/user/' + item.id">{{ item.name }}</router-link></td>
</tr>
</table>
{{item.name}
My messages属性中有一个对象数组。每个对象都有一个id属性,我想将其附加到我的to属性上。因此,如果我在messages数组中有两个ID分别为1和2的项,我希望得到如下结果:
<table>
<tr v-for="item in messages">
<td><router-link to="/user/1">{{ item.name }}</router-link></td>
</tr>
<tr v-for="item in messages">
<td><router-link to="/user/2">{{ item.name }}</router-link></td>
</tr>
</table>
{{item.name}
{{item.name}
我也试着把doing{{message.id}}放进去,但这会给我一个插值错误。如何使其呈现“to”属性中message.id的实际值?item.name属性按预期呈现 只需将
v-bind:
添加到之前
<table>
<tr v-for="item in messages">
<td><router-link v-bind:to="'/user/' + item.id">{{ item.name }}</router-link></td>
</tr>
</table>
{{item.name}
没有v-bind:
您实际上是在使用'user'+item.id
作为值。
更多的澄清检查