第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 render() 之前更新 var [React Native]

在 render() 之前更新 var [React Native]

飲歌長(zhǎng)嘯 2022-05-14 14:43:29
對(duì)于一個(gè)學(xué)習(xí)項(xiàng)目,我目前正在開(kāi)發(fā)一個(gè)移動(dòng)應(yīng)用程序,用于在本機(jī) React 中讀取 QR 碼。掃描 QR 碼后,我會(huì)將其 id 保存在歷史記錄中。當(dāng)我單擊此 ID 時(shí),我想打開(kāi)一個(gè)包含有關(guān)此 QR 碼的信息的頁(yè)面(由 API 休息檢索)。但是當(dāng)我選擇一個(gè)ID時(shí),得到的信息是之前二維碼的信息。我創(chuàng)建了一個(gè)更新信息的按鈕,但我希望它是正確的。謝謝,我附上了我的代碼和我的項(xiàng)目的 git。吉特:https ://github.com/davidsio/reactimport React, { Component } from 'react';import { StyleSheet, View, Text} from 'react-native';import QRCode from 'react-native-qrcode-svg';let getJSON = function(url, callback) {  var xhr = new XMLHttpRequest();  xhr.open('GET', url, true);  xhr.responseType = 'json';  xhr.onload = function() {    var status = xhr.status;    if (status === 200) {      callback(null, xhr.response);    } else {      callback(status, xhr.response);    }  };  xhr.send();};export default class Informations extends Component {  static navigationOptions = {    title: 'Informations',    headerBackTitle: 'Retour',    headerStyle: {      backgroundColor: '#557aca',      //Sets Header color    },    headerTintColor: '#fff',    //Sets Header text color    headerTitleStyle: {      fontWeight: 'bold',      //Sets Header text style    },    //Sets Header text of Status Bar  };  render() {    const { navigate } = this.props.navigation;    const { params } = this.props.navigation.state;    const itemValue = params ? params.itemValue : null;    const itemId = params ? params.itemId : null;    getJSON('http://elarnes.fr/get_qrcode.php?idQrCode=' + JSON.stringify(itemValue).replace(/['"]+/g, '').split(';')[1],    function(err, data) {      if (err !== null) {        console.log('Something went wrong: ' + err);      } else {        tabCode = data[0]      }    });
查看完整描述

2 回答

?
守著星空守著你

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超8個(gè)贊

你能試試這個(gè):


constructor(props) {

    super(props);

    this.state = {

        loaded: false,

        code: []

    };

}


componentDidMount() {

    getJSON('http://elarnes.fr/get_qrcode.php?idQrCode=' + JSON.stringify(itemValue).replace(/['"]+/g, '').split(';')[1],

        (err, data) => {

            if (err !== null) {

                console.log('Something went wrong: ' + err);

            } else {

                this.setState({

                    code: data[0],

                    loaded: true

                })

            }

        }

    );

}


componentDidUpdate(nextProps) {

    //this will triggered when the props changes - not needed for this

}


render() {

    if (!this.state.loaded)

        return <View />

    return (

        <View style={styles.container}>

            <QRCode

            />

            <Text>


                {tabCode["code"]}

                {tabCode["description"]}


            </Text>

        </View>

    )

}


查看完整回答
反對(duì) 回復(fù) 2022-05-14
?
慕婉清6462132

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超2個(gè)贊

import React, { Component } from 'react';

import { StyleSheet, View, Text, Button} from 'react-native';

import QRCode from 'react-native-qrcode-svg';


let code = [];



let getJSON = function(url, callback) {

  var xhr = new XMLHttpRequest();

  xhr.open('GET', url, true);

  xhr.responseType = 'json';

  xhr.onload = function() {

    var status = xhr.status;

    if (status === 200) {

      callback(null, xhr.response);

    } else {

      callback(status, xhr.response);

    }

  };

  xhr.send();

};




export default class Informations extends Component {

  static navigationOptions = {

    title: 'Informations',

    headerBackTitle: 'Retour',

    headerStyle: {

      backgroundColor: '#557aca',

      //Sets Header color

    },

    headerTintColor: '#fff',

    //Sets Header text color

    headerTitleStyle: {

      fontWeight: 'bold',

      //Sets Header text style

    },

    //Sets Header text of Status Bar

  };


  constructor(props) {

    super(props);

    this.state = {

        loaded: false,

        code: []

    };

  }


  componentDidMount() {

    const { params } = this.props.navigation.state;

    const itemValue = params ? params.itemValue : null;

    const itemId = params ? params.itemId : null;


    getJSON('http://elarnes.fr/get_qrcode.php?idQrCode=' + JSON.stringify(itemValue).replace(/['"]+/g, '').split(';')[1],

        (err, data) => {

            if (err !== null) {

                console.log('Something went wrong: ' + err);

            } else {

                this.setState({

                  code: data[0],

                  loaded: true,


                })

            }

        }

    );

  }


  componentDidUpdate(nextProps) {

    //this will triggered when the props changes - not needed for this

  }


  render() {


    if (!this.state.loaded)

        return <View />

    return (

      <View style={styles.container}>

        <QRCode

                  value={"sdbwfhjk"}

                  size={250}

                  color="black"

                  backgroundColor="white"

                  logoSize={30}

                  logoMargin={2}

                  logoBorderRadius={15}

                  logoBackgroundColor="yellow"

                />

                <Text>


                {this.state.code["code"]}

                {this.state.code["description"]}


                </Text>

      </View>

    );

  }

}

const styles = StyleSheet.create({

  container: {

    flex: 1,

    backgroundColor: 'white',

    justifyContent: 'center',

    alignItems: 'center'


  },

});


查看完整回答
反對(duì) 回復(fù) 2022-05-14
  • 2 回答
  • 0 關(guān)注
  • 106 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)