漏子专题

React 学习——forwardRef,暴漏子组件的dom元素

父组件拿到子组件的值:使用forwardRef import { forwardRef,useRef } from 'react';const Input = forwardRef((props,ref)=>{return <input type="text" ref={ref} />})const App = () => {const inputRef = useRef(null);con

React 学习——useImperativeHandle,暴漏子组件中的方法

暴露子组件的方法: import { forwardRef,useRef,useImperativeHandle } from 'react';const Input = forwardRef((props,propRef)=>{const sonRef = useRef(null);const focusHandle = () => {console.log('父组件调用子组件的方法');s

defineExpose暴漏子组件的属性和方法!!!

需求:需要在父组件中使用子组件的方法或者属性 一、在子组件中定义方法,并将其暴漏出来 首先我引入了一个抽屉组件,通过open方法设置打开抽屉,然后通过difineExpose将open方法暴漏出来。 <template><el-drawer v-model="drawer" title="请选择商品" size="70%"></el-drawer></template><script s