react 實(shí)現(xiàn)鼠標(biāo)拖拽移動(dòng) 我們可以引入一個(gè)組件是 react-rnd
即通常的引用
npm i react-rnd -S
安裝后 引用就可以了
import {Rnd} from 'react-rnd'
用的時(shí)候只需要在想要被拖動(dòng)的內(nèi)容外面套上<Rnd></Rnd>標(biāo)簽就可以了
如 (尷尬了 這個(gè)markdown不識(shí)別 箭頭函數(shù))
<Rnd
size={{ width: item.width, height: item.height }}
position={{ x: item.x, y: item.y }}
onDragStop={(e, d) => this.moveItem(e,d,item)}
onResizeStop = {(e,direction,ref,delta,position) => this.changeItem(e,direction,ref,delta,position,item)}
key={item.id}
>
<Input type="primary"
style={{
width: item.width ||'',
height: item.height || ''
}}
key={item.id} ref={'ref'+ item.id}
onDoubleClick = { e =>this.handleCheckedTxt(e, item)}
placeholder = "請(qǐng)輸入"></Input>
</Rnd>