首先這個(gè)問題困擾了菜雞很長(zhǎng)時(shí)間,在 清清 和 覺醒 倆位的領(lǐng)導(dǎo)下,把這個(gè)問題給解決了,其實(shí)沒那么復(fù)雜。
1:需要導(dǎo)出的組件要加上export default,定義為可導(dǎo)出的。
export default class 組件名 extends React.Component
如下:
export default class Detail extends React.Component
2:需要導(dǎo)出的組件,寫上導(dǎo)出叫啥。
module.export = 導(dǎo)出名稱
如下:
module.export = Detail;
導(dǎo)出組件的JS 如下:
'use strict';
import React, {PropTypes} from 'react';
import {
Text,
StyleSheet,
} from 'react-native';
const propTypes = {
onPress: PropTypes.func,
containerStyle: PropTypes.object,
text: PropTypes.string
};
export default class Detail extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<Text>測(cè)試引用</Text>
);
}
}
module.export = Detail;
導(dǎo)出完了,咱們就得引用了。。。
3:引用你得告訴RN組件從哪里來(lái),我的朋友。
import 要導(dǎo)入組件名稱 from './導(dǎo)入組件的路徑' (這里的./ 叫同級(jí)目錄,最后面的組件名不要加后綴,RN能識(shí)別又不傻)
如:
import Detail from './Buttom/Detail';
4:最后就引用這個(gè)組件名標(biāo)簽進(jìn)去就好了。
如:
<View>
<Detail />
</View>
然后就可以了,終于成功了,好羞澀呀。