Reactjs 访问非React生成的HTML节点

Reactjs 访问非React生成的HTML节点,reactjs,Reactjs,我在加价的头上写着: 它生成一个来自PHP的随机ID 我需要在AXIOS帖子中传递Attribute内容的值: submitForm (e) { e.preventDefault(); var current = this.props.currentState; axios({ url: '/save-data', method: 'POST', contentType: 'application/json', data:

我在加价的头上写着:

它生成一个来自PHP的随机ID

我需要在AXIOS帖子中传递Attribute内容的值:

submitForm (e) {
    e.preventDefault();
    var current = this.props.currentState;
    axios({
      url: '/save-data',
      method: 'POST',
      contentType: 'application/json',
      data: {
        "candidate": {
            "first_name": current.name,
            "last_name": this.state.lastName,
            "email": this.state.email,
            "university": this.state.location,
            "degree_area": this.state.degree,
            "year_of_graduation": this.state.year
        },
        "tshirt": {
            "color_id": current.activeColorTextID,
            "options": [{
                "icon_id": current.optionA.icon_id,
                "option_id": current.optionA.option_id
            }, {
                "icon_id": current.optionB.icon_id,
                "option_id": current.optionB.icon_id
            }, {
                "icon_id": current.optionC.icon_id,
                "option_id": current.optionC.icon_id
            }]
        }
      },
      headers: { 'Content-Type': 'application/json' }
    }).then(function(response){
        console.log(response);
    }); 
}
这是jQuery版本:

    $(function() {
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        $.ajax({
            url: '/save-data',
            type: 'POST',
            contentType: 'application/json',
            data: JSON.stringify({
                "candidate": {
                    "first_name": "",
                    "last_name": "",
                    "email": "",
                    "university": "UCL",
                    "degree_area": "IT",
                    "year_of_graduation": "2016"
                },
                "tshirt": {
                    "color_id": 1,
                    "options": [{
                        "icon_id": 1,
                        "option_id": 2
                    }, {
                        "icon_id": 2,
                        "option_id": 5
                    }, {
                        "icon_id": 4,
                        "option_id": 12
                    }]
                }
            }),
            dataType: 'json'
        });
    });
但我需要在反应中实现它


是否可以访问该HTML元素内容属性?

您可以轻松使用
文档。querySelector

submitForm (e) {
    e.preventDefault();
    var current = this.props.currentState;
    axios({
      url: '/save-data',
      method: 'POST',
      contentType: 'application/json',
      data: {
        "candidate": {
            "first_name": current.name,
            "last_name": this.state.lastName,
            "email": this.state.email,
            "university": this.state.location,
            "degree_area": this.state.degree,
            "year_of_graduation": this.state.year
        },
        "tshirt": {
            "color_id": current.activeColorTextID,
            "options": [{
                "icon_id": current.optionA.icon_id,
                "option_id": current.optionA.option_id
            }, {
                "icon_id": current.optionB.icon_id,
                "option_id": current.optionB.icon_id
            }, {
                "icon_id": current.optionC.icon_id,
                "option_id": current.optionC.icon_id
            }]
        }
      },
      headers: {
          'Content-Type': 'application/json',
          'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').attributes['content'].value
      }
    }).then(function(response){
        console.log(response);
    }); 
}