warning in ./node_modules/@ant-design/pro-list/node_modules/@ant-design/pro-field/es/components/ColorPicker/index.js-前端-E先生的博客
Java
MySQL
大数据
Python
前端
黑科技
大语言模型
    首页 >> 互联网 >> 前端

warning in ./node_modules/@ant-design/pro-list/node_modules/@ant-design/pro-field/es/components/ColorPicker/index.js

[导读]:warning in ./node_modules/@ant-design/pro-list/node_modules/@ant-design/pro-field/es/components/ColorPicker/index.jsexport 'ColorPicker' (imported as 'ColorPickerV5') was not found in 'antd' (possible exports: Affix, Alert, Anchor, AutoComplete, Avatar, BackTop, Badge, Breadcrumb, Button, Calendar, Card, Carousel, Cascader, Checkbox, Col, Collapse, Comment, ConfigProvider, DatePicker, Descriptions, Divider, Drawer, Dropdown, Empty, Form, Grid, Image, Input, InputNumber, Layout, List, Mentions, Menu, Modal, PageHeader, Pagination, Popconfirm, Popover, Progress, Radio, Rate, Result, Row, Segmented, Select, Skeleton, Slider, Space, Spin, Statistic, Steps, Switch, Table, Tabs, Tag, TimePicker, Timeline, Tooltip, Transfer, Tree, TreeSelect, Typography, Upload, message, notification, theme, version)...

这个是什么问题

是因为我的工程中 antd 版本是"antd": "^4.19.0",,而ColorPickerV5是从antd@5.5.0才可用的。详见官网 antd-color-picker官网

打开源码看一下  如果实在不想看源码  可以在这个文件找到报错点ColorPickerV5 找到它的使用地方 这边解释一下代码  

源码部分:

/**
 * 获取颜色组件
 * @param {boolean} [old=false] 是否使用旧版本
 * @return {*}
 */
function getColorPicker() {
  var old = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  if ((typeof old === 'undefined' || old === false) && IsIt_Render_V5()) {
    return ColorPickerV5;
  }
  return ColorPickerV4;
}

这段说的旧的不用了 直接用到了ColorPickerV5   但是你去看 上面引入的ColorPickerV5   进到antd看不到这个引入 所以会报错  解决办法很简单  改掉还是用旧的就可以了改正后代码:

/**
 * 获取颜色组件
 * @param {boolean} [old=false] 是否使用旧版本
 * @return {*}
 */
function getColorPicker() {
  var old = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  if ((typeof old === 'undefined' || old === false) && IsIt_Render_V5()) {
    return ColorPickerV4;//只需要在这个地方改为ColorPickerV4就可以了
  }
  return ColorPickerV4;
}

以下是源码全部:

import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import { compareVersions } from '@ant-design/pro-utils';
import { ColorPicker as ColorPickerV5, ConfigProvider, version } from 'antd';
import classNames from 'classnames';
import React, { useContext, useMemo } from 'react';
import { ColorPicker as ColorPickerV4 } from "./old";
// https://ant.design/components/color-picker-cn 示例颜色
import { jsx as _jsx } from "react/jsx-runtime";
var DEFAULT_PRESETS = {
  label: 'Recommended',
  colors: ['#F5222D', '#FA8C16', '#FADB14', '#8BBB11', '#52C41A', '#13A8A8', '#1677FF', '#2F54EB', '#722ED1', '#EB2F96', '#F5222D4D', '#FA8C164D', '#FADB144D', '#8BBB114D', '#52C41A4D', '#13A8A84D', '#1677FF4D', '#2F54EB4D', '#722ED14D', '#EB2F964D']
};
/**
 * 判断是否是 5.5.0 以上的版本
 * @returns
 */
function IsIt_Render_V5() {
  return compareVersions(version, '5.5.0') > -1;
}
/**
 * 获取颜色组件
 * @param {boolean} [old=false] 是否使用旧版本
 * @return {*}
 */
function getColorPicker() {
  var old = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  if ((typeof old === 'undefined' || old === false) && IsIt_Render_V5()) {
    return ColorPickerV5;
  }
  return ColorPickerV4;
}
// const ColorPicker = getColorPicker();
/**
 * 颜色组件
 * Antd > 5.5.0 的版本 使用 antd 的 ColorPicker
 * @param FieldColorPicker {
 *     text: number;
 *     moneySymbol?: string; }
 */
var FieldColorPicker = function FieldColorPicker(_ref, ref) {
  var text = _ref.text,
    type = _ref.mode,
    render = _ref.render,
    renderFormItem = _ref.renderFormItem,
    fieldProps = _ref.fieldProps,
    old = _ref.old;
  var _useContext = useContext(ConfigProvider.ConfigContext),
    getPrefixCls = _useContext.getPrefixCls;
  var ColorPicker = React.useMemo(function () {
    return getColorPicker(old);
  }, [old]);
  var prefixCls = getPrefixCls('pro-field-color-picker');
  // 5.5.0 以上版本追加 className
  var className = useMemo(function () {
    if (old) return '';
    return classNames(_defineProperty({}, prefixCls, IsIt_Render_V5()));
  }, [prefixCls, old]);
  if (type === 'read') {
    var dom = /*#__PURE__*/_jsx(ColorPicker, {
      value: text,
      mode: "read",
      ref: ref,
      className: className
      // @ts-ignore 设置无法 open
      ,
      open: false
    });
    if (render) {
      return render(text, _objectSpread({
        mode: type
      }, fieldProps), dom);
    }
    return dom;
  }
  if (type === 'edit' || type === 'update') {
    // 解决 默认的 width 100% 问题
    var style = _objectSpread({
      display: 'table-cell'
    }, fieldProps.style);
    var _dom = /*#__PURE__*/_jsx(ColorPicker, _objectSpread(_objectSpread({
      ref: ref,
      presets: [DEFAULT_PRESETS]
    }, fieldProps), {}, {
      style: style,
      className: className
    }));
    if (renderFormItem) {
      return renderFormItem(text, _objectSpread(_objectSpread({
        mode: type
      }, fieldProps), {}, {
        style: style
      }), _dom);
    }
    return _dom;
  }
  return null;
};
export default /*#__PURE__*/React.forwardRef(FieldColorPicker);


image.png


本文来自E先生的博客,如若转载,请注明出处:https://javajz.cn

留言区

联系人:
手   机:
内   容:
验证码:

历史留言

欢迎加Easy的QQ