Yuan.js 566 B

123456789101112131415161718192021222324252627282930313233
  1. import React from 'react';
  2. import { Charts } from 'ant-design-pro';
  3. const { yuan } = Charts;
  4. /**
  5. * 减少使用 dangerouslySetInnerHTML
  6. */
  7. export default class Yuan extends React.PureComponent {
  8. componentDidMount() {
  9. this.rendertoHtml();
  10. }
  11. componentDidUpdate() {
  12. this.rendertoHtml();
  13. }
  14. rendertoHtml = () => {
  15. const { children } = this.props;
  16. if (this.main) {
  17. this.main.innerHTML = yuan(children);
  18. }
  19. };
  20. render() {
  21. return (
  22. <span
  23. ref={ref => {
  24. this.main = ref;
  25. }}
  26. />
  27. );
  28. }
  29. }