如何在类中访问导入?

时间:2016-08-08 14:54:34

标签: javascript scope react-native require

在chrome中使用调试器,ImagePicker已设置,但当我尝试在select()函数中调用它时,ImagePicker未定义。

我在其他模块上遇到同样的问题,所以我怀疑它与我导入它的方式或范围问题有关。

我的代码:

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

var ImagePicker = require('react-native-image-picker');

// I tried this also, but it doesn't set at all.
// import { ImagePicker } from 'react-native-image-picker';

export class Upload extends Component {
    constructor(props) {
        super();
    }
    render() {
        return (
            <View>
                <Button
                    style={styles.button}
                    onPress={this.select.bind(this)}>
                    Upload
                </Button>
            </View>
        );
    }
    select() {
        var options = {...};

        ImagePicker.showImagePicker(options, (response) => {
        });
    }
}

0 个答案:

没有答案