组件之间的传值

组件的数据

一般组件是放置在
components文件夹下的,components是在page的下面的文件.
在这里插入图片描述

这个是组件的数据

import Taro, { Component } from 'react'//首先因为我们要使用taro所有我们要导入它
import { View, Text } from '@tarojs/components'//因为我们要使用这些标签所有我们要导入
export default class header extends Component {
    // 必须要有一个render
    render() {
        // 如何取props 这边是取在使用组件传递过来的数据
        // 我们可以this.props.title来取到值
        // console.log(this.props.title)
        const  {title} =this.props;
        
        // 变成类名的使用
        const headerCls=`${title}-header`
        return (<View className={headerCls}>
            <Text>好的哈大家啊点击</Text>
        <Text>{title}</Text>
        {/* 这个是直接引入 */}
        </View>)
    }
}

这个是需要使用组件内容的页面

import Taro, { Component } from 'react'
import { View, Text } from '@tarojs/components'
import './index.scss'
import Header from  '../components/header'//这边是找到组件的路径地址
//组件命名的值是header
export default class Index extends Component {
  componentWillMount () { }
  componentDidMount () { }
  componentWillUnmount () { }
  componentDidShow () { }
  componentDidHide () { }
  render () {   
    return (
      <View className='index'>
        {/* 这个title的内容相当于props  要把这个数据传到组件当中 */}
        <Header title="balabalabala"></Header>
        <Text>0 2121</Text>
      </View>
    )
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值