gpt4 book ai didi

javascript - 使用 Vue Bootstrap 表中另一列数据路径的 Vue Router 链接

转载 作者:行者123 更新时间:2023-12-02 22:15:05 24 4
gpt4 key购买 nike

我在 vue bootstrap 中有包含用户数据的表。我也使用 Vue Router 进入用户个人资料页面。个人资料页面路径是 /user/idNumber,我想将其路由到“名称”下。像这样的事情:

<a href="/users/idNumber"> Name </a>

我怎样才能做到这一点?

代码:

<b-table striped hover :items="usersList" :fields="fields">
<template v-slot:cell(_id)="data">
<router-link :to="`/user/${data.value}`">{{ data.value }}</router-link>
</template>
<template v-slot:cell(fullname)="data">
<router-link :to="`/user/${data.value}`">{{ data.value }}</router-link>
</template>
</b-table>

用户列表:

[{"_id":"5df9663acf06e2001742ac17","name":"Retdadada5155465","lastname":"Nienow","email":"Laverne55@yahoo.com","age":"1995","gender":"female","weight":58,"height":166,"activity":1.4,"value":3,"_createdOn":"2019-12-17T23:35:22.339Z","_updatedOn":"2019-12-19T20:57:30.588Z"},{"_id":"5df842f2cf06e2001742a8ec","name":"Retdadada516","lastname":"Nienow","email":"Laverne55@yahoo.com","age":"1993","gender":"female","weight":58,"height":166,"activity":1.4,"value":3,"_createdOn":"2019-12-17T02:52:34.183Z","_updatedOn":"2019-12-19T20:57:42.352Z"},{"_id":"5df7c972bca42200177decb4","name":"Lue","lastname":"Schneider","email":"Rosella93@yahoo.com","age":"1997","gender":"female","weight":60,"height":180,"activity":1.6,"_createdOn":"2019-12-16T18:14:10.554Z","_updatedOn":"2019-12-19T20:57:51.550Z"}]'

字段:

["_id",
{
key: "fullname",
label: "Fullname",
sortable: true,
formatter: (value, key, item) => {
return item.name + " " + item.lastname
},
},
{
key: "birthYear",
label: "Age: ",
sortable: true,
formatter: (value, key, item) => {
return new Date().getFullYear() - item.age
},
},
],

问候

最佳答案

对第二个模板的全名进行一点更改即可完成工作。第一个应该没问题,因为我已经看到了。

您只需使用 data.item 即可利用循环项目中的任何数据

<template>
<b-table striped hover :items="usersList" :fields="fields">
<template v-slot:cell(_id)="data">
<router-link :to="`/user/${data.value}`">{{ data.value }}</router-link>
</template>
<template v-slot:cell(fullname)="data">
<router-link :to="`/user/${data.item._id}`">{{ data.value }}</router-link>
</template>
</b-table>
</template>

工作沙箱:https://codesandbox.io/s/bootstrap-vue-sandbox-wvv9j

关于javascript - 使用 Vue Bootstrap 表中另一列数据路径的 Vue Router 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59417089/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com