推荐一些好用的插件,可搭配react使用

本文介绍react-sortable-hoc库的使用方法,实现元素的便捷拖拽排序,并演示了fileDialog封装函数用于图片上传的过程。同时,展示了moment库如何帮助格式化日期。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

react-sortable-hoc

作用:可以很简便地对元素进行拖拽
用法:

import { SortableContainer, SortableElement } from "react-sortable-hoc";
import arrayMove from "array-move";

const SortableList = SortableContainer(({ children }) => {
  return children;
});

const SortableItem = SortableElement(({ children }) => {
  return children;
});
		  <SortableList
            axis="y"
            lockAxis="y"
            distance={1}
            onSortEnd={({ oldIndex, newIndex }) => {
              setList(arrayMove(list, oldIndex, newIndex));
            }}
          >
          	<ul>
          		<SortableItem key={index} index={index}>
          		...
          		</SortableItem>
          	</ul>
          </SortableList>

fileDialog

作用:封装了图片上传的函数和回调
用法:

import fileDialog from "file-dialog";

fileDialog().then(file => {
    const data = new FormData();
    data.append("file", file[0]);
    data.append("imageName", "flower");
    // Post to server
  });

moment

作用:传入一个date,返回一定格式的日期
用法:

import moment from "moment";

moment().format("YYYY-MM-DD HH:mm:ss")//返回 2020-03-24 17:43:20  这种格式
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值