<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                --- title: 'react-smooth-dnd 拖拽實例' date: 2021-08-23 13:48:00 --- ![](https://img-blog.csdnimg.cn/20210823134720533.gif) ```javascript import React, { useState } from 'react' import { Container, Draggable } from 'react-smooth-dnd' import { v4 as uuidv4 } from 'uuid' export default function CardPlus() { const [toolList, setToolList] = useState([ { id: 't0', name: '1', }, { id: 't1', name: '2', }, { id: 't2', name: '3', }, ]) const [contentList, setContentList] = useState([ { id: 'c0', name: 'a', }, { id: 'c1', name: 'b', }, { id: 'c2', name: 'c', }, ]) const applyDrag = (arr, dragResult) => { const { removedIndex, addedIndex, payload } = dragResult if (removedIndex === null && addedIndex === null) return arr const result = [...arr] let itemToAdd = payload if (removedIndex !== null) { itemToAdd = result.splice(removedIndex, 1)[0] } if (addedIndex !== null) { result.splice(addedIndex, 0, itemToAdd) } return result } const handleGetChildPayload = ({type, index}) => { if (type === 'tool') { const id = uuidv4() return {...toolList[index], id} } else if (type === 'content') { return contentList[index] } } const handleCardDrop = ({ type, dragResult }) => { console.log(dragResult) if (type === 'tool') { const result = applyDrag(toolList, dragResult) setToolList(result) } else if (type === 'content') { const result = applyDrag(contentList, dragResult) setContentList(result) } } return ( <div className="m-test-wrap"> <div className="m-test-tool"> <Container orientation="vertical" onDrop={(dragResult) => handleCardDrop({ type: 'tool', dragResult })} getChildPayload={(index) => handleGetChildPayload({type: 'tool', index})} behaviour="copy" groupName="col" > {toolList.map((item) => ( <Draggable key={item.id} className="m-test-list-item"> <div>{item.name}</div> </Draggable> ))} </Container> </div> <div className="m-test-list"> <Container orientation="vertical" onDrop={(dragResult) => handleCardDrop({ type: 'content', dragResult }) } getChildPayload={(index) => handleGetChildPayload({type: 'content', index})} groupName="col" > {contentList.map((item) => ( <Draggable key={item.id} className="m-test-list-item"> <div>{item.name}</div> </Draggable> ))} </Container> </div> </div> ) } ``` 參考鏈接: [https://kutlugsahin.github.io/smooth-dnd-demo/](https://kutlugsahin.github.io/smooth-dnd-demo/)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看