是否可以将路由添加到数组而不是使用<a href>
作为字符串?
在此示例中,我创建了一个指向update-building
的链接,并将buildingId
添加为参数。
是否可以使用路由名称进行“更新构建”?
axios
.get("https://localhost:44349/api/Building/List", headers)
.then(response => {
response.data.forEach(el => {
this.dataset.push([
el.city,
el.street,
el.number,
el.projectName,
`<a href='#/update-building/${el.buildingId}'>update</a>`, // use route name instead this
]);
});
我的路由器文件:
{
path: '/update-building:buildingId',
name: 'UpdateBuilding',
component: UpdateBuilding,
props: true,
params: null,
meta: {
requiresAuth: true
}
},
答案 0 :(得分:0)
是答案!
axios
.get("https://localhost:44349/api/Building/List", headers)
.then(response => {
response.data.forEach(el => {
var url = this.$router.resolve({ name: 'UpdateBuilding', params: { buildingId: el.buildingId }}).href
this.dataset.push([
el.city,
el.street,
el.number,
el.projectName,
`<a href='#/${url}/${el.buildingId}'>update</a>`,
]);
});