【问题标题】:React Beautiful Drag and Drop反应美丽的拖放
【发布时间】:2020-05-22 06:18:03
【问题描述】:

我正在使用拖放元素创建一个可拖动列表,问题是 DND 元素的动画从指针移动,导致拖动到其他拖放元素时出现问题。 https://codesandbox.io/s/green-microservice-j7h9v?fontsize=14&hidenavigation=1&theme=dark 在这里,我编写了一个我想要实现的示例,它还有一些其他不重要的错误。

【问题讨论】:

    标签: reactjs drag-and-drop react-beautiful-dnd


    【解决方案1】:

    首先,您的索引不是字符串而是整数 (Es: index={1}),您应该更新状态以呈现组件。使用反应钩子来更新它或基于类的组件。

    很抱歉,我没有编写工作代码,但这里有一个基于类的组件的示例。

    https://codepen.io/alexreardon/project/editor/ZyNMPo

      onDragEnd (result) {
        // dropped outside the list
        if(!result.destination) {
           return; 
        }
    
        const items = reorder(
          this.state.items, 
          result.source.index, 
          result.destination.index
        );
    
        this.setState({
          items
        });
      }
    

    【讨论】:

    • 我的问题是,如果我在 react 可拖动组件中有一个 DND 元素,那么动画就会移动,我可以解决沙箱中的其他错误
    猜你喜欢
    • 2022-09-30
    • 2020-12-11
    • 2019-07-25
    • 2021-01-15
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 1970-01-01
    相关资源
    最近更新 更多