(vue)给对象中添加属性,新对象在另一个页面展示
场景:
组件:
data() {
interfaceDetail: {}, //存放新数据的对象
}
//编辑按钮
toEdit(item) {
var uid = item.uid;
findApiMod({
userName: this.loginName,
uid: uid,
}).then((res) => {
this.interfaceDetail.content = res.data.data;
this.interfaceDetail.content.uid = uid;
console.log(this.interfaceDetail);
this.$router.push({
path: "/interface/queryService",
query: {
// url的参数, 类似get请求的传参
data: JSON.stringify(this.interfaceDetail),
},
});
});
},
queryService页面:
mounted() {
if (this.$route.query.data) {
var data = JSON.parse(this.$route.query.data);
if (data) {
this.flag = false;
this.uid = data.content.uid;
this.title = data.content.name;
this.url = data.content.url;
this.type = data.content.type;
this.graphs = data.content.graphs;
this.algorithm = data.content.algorithm;
this.responseBody = data.content.responseBody;
this.uri = data.content.url.substr(
data.content.url.lastIndexOf("/") + 1
);
}
}
},
结果:
编辑页面: