簡體   English   中英

React Native - 在同一個類上訪問靜態變量

[英]React Native - Accessing static variable on same class

我最近剛從android轉到React Native。 所以需要一些幫助。 為什么我無法訪問同一個類的變量,例如當我從另一個類調用URL_API_SERVER時,它會給我'Undefined / api / v2'。

class Constant {
    static BASE_URL = 'https://xxxxx';
    static URL_API_SERVER = this.BASE_URL + '/api/v2';
    static STATIC_BASEURL = this.BASE_URL + '/static';
    static URLSTRING_FAQ = this.STATIC_BASEURL + '/FAQ.html';
    static URLSTRING_TOU = this.STATIC_BASEURL + '/TOU.html';
}

export default Constant;

由於您使用的是static變量,因此無法使用this 您可以像下面一樣訪問靜態變量。

class Constant {
    static BASE_URL = 'https://xxxxx';
    static URL_API_SERVER = Constant.BASE_URL + '/api/v2';
    static STATIC_BASEURL = Constant.BASE_URL + '/static';
    static URLSTRING_FAQ = Constant.STATIC_BASEURL + '/FAQ.html';
    static URLSTRING_TOU = Constant.STATIC_BASEURL + '/TOU.html';
}

export default Constant;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM