Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问发送请求后如何获取服务器返回的数据? #26

Open
xtrn143 opened this issue Mar 14, 2024 · 1 comment
Open

请问发送请求后如何获取服务器返回的数据? #26

xtrn143 opened this issue Mar 14, 2024 · 1 comment

Comments

@xtrn143
Copy link

xtrn143 commented Mar 14, 2024

如题:

/** 
     * 根据用户输入的提问,向知识库获取回答
     * @param question 用户提问
     * @return UseAxiosReturn 知识库回答
     */
    function getAnswerList(id: string, question: string) {
        useAxiosApi(`/knowledgebase/${id}/search`, {
            method: 'GET',
            params: { query: question },
            headers: {
                'Content-Type': 'application/json'
            }
        }).then((res) => {
            console.log(res)
            //请问这里要怎么样才能取出数据?
        }).catch(() => {

        });
    }

打印res之后的内容为:

{
    "code": 200,
    "items": [
        {
            "content": "content",
            "identify": "1767763096417337344",
            "metadata": {
                "seq_num": 54
            },
            "score": 0.7338999207181424
        },
        {
            "content": "content2",
            "identify": "1767763096417337344",
            "metadata": {
                "seq_num": 12
            },
            "score": 0.6277636422458995
        },
    ],
    "totalCount": 10
}

res的类型为res: StrictUseAxiosReturn<any, AxiosResponse<any, any>, any>,那我怎么样才能取到我想要的items里的内容呢。还没有学ts就开始写项目了,但时间又比较紧,感谢大佬了

@xxxsf
Copy link
Owner

xxxsf commented Mar 15, 2024

res.items 不就取到了吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants