React native 在react native中的常量值中设置mobx存储

React native 在react native中的常量值中设置mobx存储,react-native,api,axios,mobx,asyncstorage,React Native,Api,Axios,Mobx,Asyncstorage,如何使用mobx obeserve数据设置常量值?因为我不知道如何定义这里的道具 export const BASE_URL = base_url_from_mobx 我在这个函数中有一些数据。从那里我将有一些机密数据和一个基本的网址。这是一个本机模块 ApiKeys.getApiKeys((data)=>{ let secureData = JSON.parse(data) } 我有一个api.js文件,其中设置了拦截器并设置了基本url,如下所示 const api = a

如何使用mobx obeserve数据设置常量值?因为我不知道如何定义这里的道具

export const BASE_URL = base_url_from_mobx
我在这个函数中有一些数据。从那里我将有一些机密数据和一个基本的网址。这是一个本机模块

ApiKeys.getApiKeys((data)=>{
    let secureData = JSON.parse(data)
}
我有一个api.js文件,其中设置了拦截器并设置了基本url,如下所示

const api = axios.create({
    baseURL: BASE_URL,
    timeout: 10 * 1000,
    headers: {
        'content-type': 'application/json',
    }
});
const api = axios.create({
    // baseURL: BASE_URL,
    baseURL: (JSON.parse(AsyncStorage.getItem(SECURE_KEY))).SOHOJ_APP_API_BASE_URL_DEVELOPMENT,
    timeout: 10 * 1000,
    headers: {
        'content-type': 'application/json',
    }
});
这里定义了BASE\u URL,并将其导出为constants.js文件中的const,但现在我想根据从函数中获得的值进行设置。 这可以做到,如果我可以做如下

const api = axios.create({
    baseURL: BASE_URL,
    timeout: 10 * 1000,
    headers: {
        'content-type': 'application/json',
    }
});
const api = axios.create({
    // baseURL: BASE_URL,
    baseURL: (JSON.parse(AsyncStorage.getItem(SECURE_KEY))).SOHOJ_APP_API_BASE_URL_DEVELOPMENT,
    timeout: 10 * 1000,
    headers: {
        'content-type': 'application/json',
    }
});
但它给了我这样的问题

我该怎么做呢。我使用api.js

api
    .post('api_end_point',parameters,headers)
    .then(response=>{

    })
    .catch(error =>{

    })

谢谢

这意味着您的
异步存储.getItem(SECURE\u KEY)
存在一些问题,可能它不是一个正确的json对象。请执行
异步存储.getItem(SECURE\u KEY)
的console.log,看看您得到了什么值。

好的,但是我如何在那里得到基本url?将console.log of AsyncStorage.getItem的输出粘贴到这里(SECURE_KEY)当我这样做的时候..AsyncStorage.getItem(SECURE_KEY).然后(value=>{console.log('SECURE_KEY:',value)})我得到了数据,但是我在里面做不到…请看我的const apii没有得到你?我只是问你从AsyncStorage.getItem(SECURE_KEY)得到了什么输出?我得到一个json字符串作为输出..然后我把它转换成一个json对象..但问题在于promise