React 获取虚拟dom节点的两种方法

第一种常规做法:

<div className="confirm-money" ref="totalNeedPayRef">
  { totalNeedPay }
</div>

import React from 'react';
import { findDOMNode } from 'react-dom';

const { totalNeedPayRef } = this.refs;
const totalNeedPay = findDOMNode(totalNeedPayRef).innerText.replace(/,/g, '') * 1;

第二种超前做法:

<span className="price-num" ref={(ref) => this.payMoneyRef = ref}>investMoney</span>

console.log(this.payMoneyRef.innerText);

相关推荐