在子组件中写需要被使用的方法
const setCode = (code: string) => {
// 在父组件里面再调用一次
init(code);
};
defineExpose({ setCode });
在父组件中
<codemirror
style="position: relative"
ref="codeRef"
:code="codeDate"
></codemirror>
命名ref
const codeRef = ref(null);
const zi = codeRef.value;
zi.setCode(codeDate.value);
即可