-
Notifications
You must be signed in to change notification settings - Fork 0
/
App11.js
37 lines (36 loc) · 1.09 KB
/
App11.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React, { Component } from 'react'
import { Text, View, Button } from 'react-native'
import Async from '@react-native-async-storage/async-storage'
export default class App11 extends Component {
_store=()=>{
let user={name:'MRC',age:21}
Async.setItem("user",JSON.stringify(user))
.then(()=>console.log("储存成功!!!"))
}
_read=()=>{
//异步函数调用:()=>{};.then(()=>{});await
Async.getItem("user")
.then(rs=>{
let user=JSON.parse(rs)
console.log(user.name,user.age)
})
.catch(err=>{
console.log("数据找不到!!!")
})//错误处理
}
_delete=()=>{
Async.removeItem("user")
.then(()=>{
console.log("删除成功!!!")
})
}
render() {
return (
<View>
<Button title="存数据" onPress={this._store}/>
<Button title="取数据" onPress={this._read}/>
<Button title="删除数据" onPress={this._delete}/>
</View>
)
}
}