你需要使用一些 Javascript :)
只需向您的 ancor 元素添加一个 id 属性:
<a id="anchor" href="https://develop.lightning.force.com/lightning/r/Contact//view">{doctor.Name}</a>
然后动态设置。
var a = document.getElementById('anchor');
var id = 0x323214343;
a.href = `https://develop.lightning.force.com/lightning/r/Contact/{{id}}/view`;
在你的 lwc 的 JS 文件中,你可以为那个 url 公开一个 getter,它应该是相对的而不是绝对的:
get doctorURL() {
// this is a relative url.
return `/lightning/r/Contact/${this.doctor.Id}/view`;
}
我假设 Id 是
doctor
对象的属性。<a href={doctorURL}>{doctor.Name}</a>
请注意,
document.getElementById();
在 LWC 中不起作用。