React native 使用axios使用restapi

React native 使用axios使用restapi,react-native,react-redux,axios,React Native,React Redux,Axios,我想在react native中使用带有axios的rest api。我想获得一个特定的项目,因此URL如下/book/6377378如何使用axios传递该数字id 我到目前为止所做的: import axios from 'axios'; import config from '../Config' const requestHelper = axios.create({ baseURL: config.prodBaseUrl, }); export default {

我想在react native中使用带有axios的rest api。我想获得一个特定的项目,因此URL如下/book/6377378如何使用axios传递该数字id

我到目前为止所做的:

import axios from 'axios';
import config from '../Config'

const requestHelper = axios.create({
    baseURL: config.prodBaseUrl,
});

export default {
    books: {
        getAll: () => requestHelper({
            url: 'books',
            method: 'get',
        }),
        getOne: bookId => requestHelper({
            url: 'books/' + bookId, // '5f914f39342ba5b506cb386f',
            method: 'get',
        }),
        create: data => requestHelper({
            url: 'books',
            method: 'post',
            data,
        }),
    },
};
目前的代码不起作用。但如果我将图书id硬编码为:

url: 'books/' + '5f914f39342ba5b506cb386f',
要调用我所做的操作:

const bookId = this.props.navigation.getParam('bookId')

console.log(bookId);   // The bookId is NOT NULL. Is CORRECT!

getChatRoom(bookId);
我的错在哪里


谢谢

使用反勾号而不是单引号更改URL,如下所示

url: `books/${bookId}`
bookId是变量。要在字符串中添加变量,必须使用反勾号并将变量放置在${variable_name}中