我创建了一个 BaseComponent ,它将在所有其他组件中扩展:
import React, { Component } from 'react'
import { ScrollView, Text, Image, View, TouchableOpacity, TextInput } from 'react-native'
export default class BaseComponent extends Component {
}
在我的其他组件中,我使用它如下:
import BaseComponent from '../Components/BaseComponent'
export default class LoginScreen extends BaseComponent {
}
现在我已经导入了View
,ScrollView
等在 BaseComponent 中,但是当我尝试在子组件中使用它时,它显示错误can'find variable View
.
如何在 ChildComponent 中使用导入的 BaseComponnet 类?
在 Nodejs 中,每个文件都被视为一个模块,它有自己的变量范围。当您将变量导入文件时说React or ScrollView
例如,您将此变量添加到模块作用域,但不添加到全局作用域。
的情况下webpack
您可以使用ProvidePlugin
少数进口为全球
new webpack.ProvidePlugin({
React: 'react' // ReactJS module name in node_modules folder
})
之后,您可以跳过在所有模块中导入这些变量变量:webpack
会自己做,在需要的地方处理它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)