react-native笔记(二)

235 阅读1分钟

10. fetch 网络层

fetch response api

//返回值text
response.text().then(function (text) {
    console.log('response.text()='+ text);
  });

箭头函数

Promises

reactnative 资料

9.async-storage 数据储存

数据层

import AsyncStorage from '@react-native-community/async-storage';

storeData = async () => {
  try {
    await AsyncStorage.setItem('@storage_Key', 'stored value')
  } catch (e) {
    // saving error
  }
}

getData = async () => {
  try {
    const value = await AsyncStorage.getItem('@storage_Key')
    if(value !== null) {
      // value previously stored
    }
  } catch(e) {
    // error reading value
  }
}
 

8.SHA-256 加密使用

sha256 官网

var hash = require('hash.js')
var hpw = hash.sha256().update(this.state.password).digest('hex')

7.基础用法

react native:(基本常用JS语法)

    let strMap = new Map();
       for (let k of Object.keys(res.data)) {
        console.log(`k `+k);
        console.log(`res[k]`+res.data[k]);
        strMap.set(k,res.data[k]);
    }

6.async 异步

async await配合使用 即可实现异步 async

5. 调试打log

react-native log-android

console.log('请求url: ', url);

4.JsonUtils 和字符串操作

字符串操作

JsonUtils

3.查看version

npm info react-native

2.npmjs 资源库

npmjs 库

1.报错异常

Install the library using either Yarn:

yarn add @react-native-community/netinfo

or npm:

npm install --save @react-native-community/netinfo