在React JS中使用onclick事件处理Api调用

问题描述

**大家好,有人可以建议我使用react js中的onclick处理api调用的最简单方法,我也尝试了其他方法,但是我总是收到错误“ TypeError:无法读取未定义的属性'viewdata'”,任何人都可以建议我换种方式 [![在此处输入图片描述] [1]] [1] [1]:https://i.stack.imgur.com/aYOnu.png `输入

//my api call
handleClick() {
        get("https://get-docs.p.rapidapi.com/api/Claim/GetDocumentList", {
            "content-type": "application/octet-stream",            "x-rapidapi-host": "get-docs.p.rapidapi.com",            "x-rapidapi-key": "dd9aad1168msh7ab81579e00d2f7p17fd9fjsnb9446ab25384",            "useQueryString": true
        }, {"params": "claimId: dd61c35e-3edd-ea11-a813-000d3a795762"}
            , this.viewdata, (failure) => { console.log(failure) });
    }

//response if its success
viewdata = response => {        
        let viewdoc = [];
        for (let i = 0; i < response.data.length; i++) {
            let currentDoc = response.data[i];
            viewdoc.push({
                key: '' + i,                document: currentDoc.caseTitle,                filed_by: currentDoc.partyName,                date: currentDoc.createdDate,                status: currentDoc.documentStatus,            });
        };
        this.setState({
            viewdoc: viewdoc,        });
        console.log(viewdoc)
    }

//where am calling api in button
const columns = [
    {
        title: 'Document'       
    },    {
        key: 'filed_by'
    },    {
        dataIndex: 'date'
    },    {
        title: 'Status'       
         render: (status) => (
            <span style={{ fontWeight: 600, color: "black" }}>{status}</span>
        ),    },    {
        title: 'Action',        key: 'action',        render: (text, record) => (
            <div size="small">
                <a href="#" onClick={this.handleClick.bind(this)}View File</a>
            </div>
        ),];

`**

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)