在父组件定义函数
TS
setup(props) {
const onChangeValue = (value: number) => {
console.log('frozeRule:', value);
};
return { onChangeValue };
}
VUE
<c-child-comb @change="onChangeValue" />
子组件调用函数,emit
方式一,VUE
<div @click="(val: any) => $emit('change', val)"></div>
方式二,TS
export default defineComponent({
emits: ['change'],
setup(props, { emit }) {
const changeKey = (key: number) => {
emit('change', key);
};
},
})