zoukankan      html  css  js  c++  java
  • 移动端的拖拽排序在react中实现 了解一下

    最近做一个拖拽排序的功能找了好几个有一个步骤简单,结合redux最好不过了,话不多说上代码

    第一步:

    npm install react-draggable-tags --save

    第二步 sort.js

    
    
     1 import React from 'react';
     2 import ReactDOM from 'react-dom';
     3 import {DraggableArea} from 'react-draggable-tags';
     4 import './sort.scss';
     5 
     6 class Sort extends React.Component {
     7     //定义组件状态
     8     state = {
     9         initialTags:[
    10             {id: 1, name: 'apple'}, {id: 2, name: 'watermelon'}, {id: 3, name: 'banana'},
    11             {id: 4,  name: 'lemon'}, {id: 5, name: 'orange'}, {id: 6, name: 'grape'},
    12             {id: 7, name: 'strawberry'}, {id: 8, name: 'cherry'}, {id: 9, name: 'peach'}]
    13     }
    14     render() {
    15       return (
    16         <div className="Simple">
    17             <DraggableArea
    18                 initialTags={this.state.initialTags}
    19                 render={({tag}) => (
    20                 <div className="tag">
    21                     {tag.name}
    22                 </div>
    23                 )}
    24                 onChange={(tags) => console.log(tags)}
    25             />
    26         </div>
    27       );
    28     }
    29   }
    30   export default Sort;
    
    
    
    
    
    第三步 :sort.css
    .Simple {
        border: 1px solid #E9E9E9;
        border-radius: 4px;
         294px;
        height: 220px;
        padding: 5px;
      }
      .tag {
        margin: 3px;
        font-size: 13px;
        border: 1px dashed #cccccc;
        border-radius: 4px;
        padding: 0 8px;
        line-height: 30px;
        color: #666666;
        background: rgba(255, 255, 255, 0.7);
      }
    

      

    以上就是可以拖拽排序的组件啦! 只需要控制state 中的initialTags就可以啦!.

     
  • 相关阅读:
    一只小小麻雀——基于语法分析工具Gold开发的加减法解释器
    儿子和女儿——解释器和编译器的区别与联系
    商用密码企业调研(必做)
    create dict in python
    sequence in python
    Cpp pointers
    sorted: list sort in python
    the array.length() of C++
    string of Cpp
    srandom and random
  • 原文地址:https://www.cnblogs.com/wenbodeboke/p/Wenwen.html
Copyright © 2011-2022 走看看