父组件:
<a-button type="primary" @click="lookInterfaceInfo(record)"
>查看</a-button
>
<!-- 查看接口信息弹框 -->
<look-interface v-if="flag" :interFaceProps="interFaceProps" >
</look-interface>
methods: {
//查看单个接口信息
lookInterfaceInfo(value) {
console.log(value, "lookInterfaceInfo");
this.flag =true;
this.interFaceProps.modelSwitch =true;
this.interFaceProps.id= value.id;
},
}
子组件:
export default {
name: "lookInterface",
props: ["interFaceProps"],
components: {},
data() {
return {
data: [],
};
},
created() {},
watch: {
"interFaceProps.id": function (newValue, oldValue) {
console.log(newValue, "newValue");
console.log(oldValue, "oldValue");
if (newValue) {
const url = `/api/interface-api/getApi?id=${newValue}`;
this.$Ajax.get(url).then((e) => {
if (e.success) {
console.log(e.success);
this.data.push(e.result);
}
});
} else {
if (this.interFaceProps.id) {
const url = `/api/interface-api/getApi?id=${this.interFaceProps.id}`;
this.$Ajax.get(url).then((e) => {
if (e.success) {
// console.log(e.success);
this.data.push(e.result);
} else {
this.data = [];
}
});
}
}
},
},
mounted() {
console.log(this.interFaceProps.id, "this.interFaceProps.id");
this.getInterFaceinfo();
},
getInterFaceinfo() {
const url = `/api/interface-api/getApi?id=${this.interFaceProps.id}`;
this.$Ajax.get(url).then((e) => {
if (e.success) {
//console.log(e.success);
this.data.push(e.result);
} else {
this.data = [];
}
});
},
总结:
通过在子组件监听props里面id值变化,最开始启用mounted的方法,后面根据变化的props执行watch里面的方法。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。