when I fetch data from server side, I got an error which is...ManageInventory.js:7 Uncaught (in promise) TypeError: res.json is not a function

when I fetch data from server side, I got an error which is...ManageInventory.js:7 Uncaught (in promise) TypeError: res.json is not a function

这是我的 index.js 来自服务器

const express = require('express');
const cors = require('cors');
const items = require('./data.json');
const port = process.env.PORT || 4000;
const app = express();
app.use(cors())
app.use(express.json())
app.get('/', (req, res) => {
    res.send('Hello....Assalamualaikum')
})
app.get('/items', (req, res) => {
    res.send(items);
})
app.listen(port, () => {
    console.log('listening from', port)
})

这是来自前端的ManageInventory.js

import axios from 'axios';
import React, { useState } from 'react';
const ManageInventory = () => {
const [items, setItems] = useState([])
axios({
        method: 'get',
        url: 'http://localhost:4000/items'
    })
        .then(res => res.json())
        .then(data => console.log(data))
    return (
        <>
            <h1>This is manage Inventory page</h1>
        </>
    );
};

export default ManageInventory;

为什么显示 res.json() 不是函数?

写res.data而不是res.json() Axios 负责为我们自动解析响应,因此我们不必调用任何其他方法。

Whwn 我像下面这样调用 axios 那么我的问题就解决了。谢谢大家提供有用的信息。

axios.get('http://localhost:4000/items')
            .then((response) => {
                console.log(response.data)
            })