02-Taro页面编写和传值

本文介绍了Taro页面的编写和传值过程,包括State局部状态管理、组件编写与传值、页面跳转和参数传递、请求远程数据以及需要注意的事项。同时,提到了在不同端如微信小程序、百度小程序和H5中如何处理多端组件。此外,建议在开发过程中避免在componentDidMount中使用this.setState,并给出了Taro项目的实战链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

02-Taro页面编写和传值

上回说到Taro打造hello-world应用。废话不多说,直接上肉菜

State局部状态

export default class Index extends Component {
  config = {
    navigationBarTitleText: '首页'
  }
  state = {
    name: "hello 前端骚年"
  }
  render () {
    const { name } = this.state
    return (
      <View className='index'>
        <Text>{name}</Text>
      </View>
    )
  }
}

组件编写和传值

mkdir -p src/components/child
cd src/components/child
touch index.jsx

编写组件,代码如下

import Taro, { Component } from '@tarojs/taro'
import PropTypes from 'prop-types'
import { View, Text } from '@tarojs/components'
export default class Child extends Component {
  propTypes = {
    childName: PropTypes.string
  }
  defaultProps = {
    childName: 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值