使用MarkDown父子组件绑定
父组件
<a-form-item field="content" label="题目内容">
<MdEditor :value="form.content" @change="handleContentChange" />
</a-form-item>
const handleContentChange = (value : string) => {
form.content = value;
};
子组件
<Editor :value="value" @change="handleChange" />
interface Props {
value : string;
mode ?: string;
handleChange : (v : string) => void;
}
const props = withDefaults(defineProps<Props>(), {
value: () => '',
mode: () => 'split',
handleChange: (v : string) => {
console.log(v); // This should pass the updated value to the parent component
},
});
const handleChange = (value : string) => {
props.handleChange(value); // Update the value in the parent component
}