【问题标题】:Get base URL from Axios - react native从 Axios 获取基本 URL - 反应原生
【发布时间】:2020-06-02 18:39:29
【问题描述】:

是否可以从 axios 获取基本 URL 并将其存储到变量中?

const instance = axios.create({
  baseURL: "http://192.168.0.103/api",
});

我想做的是..

const photo= "HTTP://192.168.0.103/" + image-Path;

这是可行的,但我不想在这里使用地址(因为我已经在 axios 文件中声明了它,我不想重复它几页),而是我想从 axios 获取它并使用在这里。

有可能吗?

【问题讨论】:

    标签: react-native axios


    【解决方案1】:

    这会起作用

        const axios = require('axios');
    
        const api = axios.create({
        baseURL: "http://www.google.com.pk"
        });
    
        console.log(api.defaults.baseURL)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-31
      • 1970-01-01
      相关资源
      最近更新 更多