您的位置:首页 > 游戏 > 手游 > 公司logo设计费_义乌seo_seo公司外包_他达拉非片正确服用方法

公司logo设计费_义乌seo_seo公司外包_他达拉非片正确服用方法

2024/10/4 20:45:17 来源:https://blog.csdn.net/weixin_39494582/article/details/142598799  浏览:    关键词:公司logo设计费_义乌seo_seo公司外包_他达拉非片正确服用方法
公司logo设计费_义乌seo_seo公司外包_他达拉非片正确服用方法

vue3 父子组件调用

父组件调用子组件方法 子组件使用defineExpose将方法抛出

父组件定义 function,子组件通过 defineExpose 暴露方法,父组件通过 ref 获取子组件实例,然后通过 ref 获取子组件方法。

// 父组件
<template><div><el-button @click="handleClick">点击显示侧边抽屉</el-button><ChildComponent ref="childRef" /></div>
</template><script setup lang="ts">
import ChildComponent from './ChildComponent.vue';const childRef = ref(null);function handleClick() {let row = '这是父组件给子组件弹窗抽屉传递分参数';childRef.value.showDrawer(row);
}
</script>
// 子组件
<template><div><el-drawer v-model="drawerVisible" title="这是子组件" size="70%" class="drawer-class"><div>这是子组件 --- {{ parentRow }}</div></el-drawer></div>
</template><script setup lang="ts" name="">
const drawerVisible = ref(false);
const emit = defineEmits(['detail']);
const parentRow = ref('');
// 显示弹窗
const showDrawer = (row) => {drawerVisible.value = true;parentRow.value = row;
};
defineExpose({showDrawer,
});
</script>

子组件调用父组件方法 defineEmits

// 父组件
<template><div><el-button @click="handleClick">点击显示侧边抽屉</el-button><ChildComponent ref="childRef" @childLoad="onLoad" /></div>
</template><script setup lang="ts" name="">
import ChildComponent from './ChildComponent.vue';const childRef = ref(null);
// 父组件调用子组件方法 --- 开始
function handleClick() {let row = '这是父组件给子组件弹窗抽屉传递分参数';childRef.value.showDrawer(row);
}
// 父组件调用子组件方法 --- 结束// 子组件调用父组件方法 --- 开始
function onLoad(row) {console.log('通过子组件点击按钮,触发父组件方法,并传递参数', row);
}
// 子组件调用父组件方法 --- 结束
</script>
// 子组件
<template><div><el-drawer v-model="drawerVisible" title="这是子组件" size="70%" class="drawer-class"><div>这是子组件 --- {{ parentRow }}</div><el-button type="success" @click="handleChildClick">点击按钮父组件会打印值</el-button></el-drawer></div>
</template><script setup lang="ts" name="">
const drawerVisible = ref(false);
const parentRow = ref('');// 父组件调用子组件方法 --- 开始
const showDrawer = (row) => {drawerVisible.value = true;parentRow.value = row;
};
defineExpose({showDrawer,
});
// 父组件调用子组件方法 --- 结束// 子组件调用父组件方法 --- 开始
const emit = defineEmits(['childLoad']);
function handleChildClick() {emit('childLoad', '子组件加载完成');
}
// 子组件调用父组件方法 --- 结束
</script>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com