vue.js - 如何将用户 ID 附加到 Vue Data 对象中的链接
问题描述
我正在尝试使用 Vuetify 将用户 ID 附加到链接。为了最大限度地减少 HTML 标记,我将链接放在一个数组中,我使用 v-for 循环访问该数组。我似乎无法将数据添加到字符串的末尾。
可以使用 {{user.uid}} 从组件的其余部分访问数据。
这是我的数据对象:
data: () => ({
drawer: false,
items: [
{ title: 'Home', link: '/' },
{ title: 'Profile', link: '/profile/{{user.uid}}' }
],
}),
computed: {
...mapState({
user: state => state.user.user
})
},
这是我的循环部分:
<template v-for="item in items">
<v-list-item :key="item.title" :to="item.link">
该链接应显示“profile/SEADpZAC5uYthxmHsOhNQeKb2XA3”,但它实际上是在打印“profile/{{user.uid}}”而不是附加 id。
希望这只是一个语法问题!免责声明:我仍然是一个初学者......
谢谢!
解决方案
这是一个静态值,它应该是动态的,使用以下语法:
<v-list-item :key="item.title" :to="item.link === '/profile/' ?
item.link + user.uid:
item.link ">
data: () => ({
...
{
title: 'Profile',
link: '/profile/'
}
...
}),
computed: {
...mapState({
user: state => state.user.user
})
},
推荐阅读
- java - 使用 mysql 在 Spring Boot 应用程序中避免“设置会话事务读取”
- python - 找到数组低于某个阈值的第一个索引(并保持低于一段时间)
- monaco-editor - 摩纳哥编辑器如何检查模型更改?
- javascript - 当我更改组件时,如何重新定义减速器的初始状态
- vba - 运行时错误“-2147417848 (80010108)”:对象“_Worksheet”的方法“单元格”失败
- servicestack - 如何测试用户是否在 ServiceStack 中的服务实现中具有角色
- java - 获取 java.lang.IllegalStateException:未找到线程绑定请求
- python - 第 1 行带有打印语句的错误令牌
- cakephp - 如何在 CakePHP3 中正确使用 group by
- c# - Azure 服务的 .Net Core 异步方法