Yuan.js 543 B

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