我有一个 item.channelId ,我想在 href 中使用它。它应该实现这样的目标:
<a :href="https://youtube.com/${item.channelId}">{{
item.channelTitle
}}</a>
Run Code Online (Sandbox Code Playgroud)
如何将 item.channelId 放入 href 中?
尝试使用
<a :href="'https://youtube.com/'+item.channelId">{{item.channelTitle}}</a>
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,属性值被视为变量中的值href的字符串和'https://youtube.com/'item.channelId
如果您想使用模板文字,请尝试
<a :href="`https://youtube.com/${item.channelId}`">{{item.channelTitle}}</a>
Run Code Online (Sandbox Code Playgroud)
对于模板文字,变量值写入${}语法内部,整个字符串将包含在反引号 (` `) 内