Adi*_*jaz 3 javascript react-native expo
我是反应原生的新手。我正在学习它,但我遇到了一个问题expo document picker
。我使用文档选择器,但它不显示任何内容,或者有时会给出承诺拒绝错误。今天我被困在这个问题上很久了。
上传.js
import React, { useState } from "react";
import {
StyleSheet,
Text,
View,
TextInput,
Button,
TouchableOpacity,
} from "react-native";
import * as DocumentPicker from "expo";
const UploadFile = () => {
pickDocument = async () => {
let result = await DocumentPicker.getDocumentAsync({});
console.log(result.uri);
console.log(result);
};
return (
<View style={styles.background}>
<Text style={styles.file}>Upload CSV File</Text>
<View style={styles.button}>
<TouchableOpacity>
<Button
title="upload your file"
color="black"
onPress={pickDocument}
/>
</TouchableOpacity>
</View>
</View>
);
};
const styles = StyleSheet.create({
background: {
backgroundColor:
"radial-gradient(ellipse at left bottom, rgb(163, 237, 255) 0%, rgba(57, 232, 255, 0.9) 59%, rgba(48, 223, 214, 0.9) 100% )",
},
file: {
color: "black",
marginHorizontal: 145,
},
button: {
marginHorizontal: 60,
},
});
export default UploadFile;
Run Code Online (Sandbox Code Playgroud)
我想上传一个文件。
其次,你的进口声明是错误的
在第三行你写了
import * as DocumentPicker from 'expo';
但你必须写import * as DocumentPicker from 'expo-document-picker';
我已经改正了。检查一次。
import React, { useState } from "react";
import {
StyleSheet,
Text,
View,
TextInput,
Button,
TouchableOpacity,
} from "react-native";
import * as DocumentPicker from "expo-document-picker";
const UploadFile = () => {
const pickDocument = async () => {
let result = await DocumentPicker.getDocumentAsync({});
console.log(result.uri);
console.log(result);
};
return (
<View style={styles.background}>
<Text style={styles.file}>Upload CSV File</Text>
<View style={styles.button}>
<TouchableOpacity>
<Button
title="upload your file"
color="black"
onPress={pickDocument}
/>
</TouchableOpacity>
</View>
</View>
);
};
const styles = StyleSheet.create({
background: {
backgroundColor:
"radial-gradient(ellipse at left bottom, rgb(163, 237, 255) 0%, rgba(57, 232, 255, 0.9) 59%, rgba(48, 223, 214, 0.9) 100% )",
},
file: {
color: "black",
marginHorizontal: 145,
},
button: {
marginHorizontal: 60,
},
});
export default UploadFile;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8042 次 |
最近记录: |