子组件创建和传值
父组件如下:
import Taro, { useState } from "@tarojs/taro";
import { View, Button, Text } from "@tarojs/components";
import { connect } from "@tarojs/redux";
import { add, minus, asyncAdd } from "../../actions/counter";
import "./index.less";
import Top from '../../compent/top/top'
function Index() {
const [username, setUserName] = useState("mingming");
return(
<View>
<Top props_username={username}></Top>
<Text>
{username}
</Text>
</View>
)
}
export default Index
子组件如下:
import { View, Text } from "@tarojs/components";
function Top(props) {
return (
<View>
<Text>完美的头部</Text>
<View>
<Text>完美的头部的{props.props_username}</Text>
</View>
</View>
);
}
export default Top;