子页面:
<template><div><!-- 子组件模板内容 --></div>
</template><script>
export default {methods: {submitForm:function() {// 需要等待完成的操作return new Promise((resolve, reject) {this.$refs["form"].validate((valid) => {if (valid) {updateData(this.form).then((res) => {console.log("修改成功>>" + res);resolve(true);});} })});}}
}
</script>
父页面:
<template><div><!-- 父组件模板内容 --></div>
</template><script>
import baseForm from './baseForm.vue';export default {components: {baseForm},methods: {async beforeHandleTabsClick(index) {if (this.activeTabsIndex === "1") {let reValidState = await this.$refs.baseForm.sumbitForm();console.log("reValidState>>" + reValidState);if (reValidState) {return true;}return false;}},}
}
</script>
这样就可以在切换的时候等待添加方法完成,不然会因为生命周期的问题拿不到添加后的编号