Taro开发之——组件库之基础组件(12)

一 概述

  • 官方基础组件
  • 类组件和功能组件
  • 基础组件Text示例

二 官方基础组件

1
2
3
4
5
6
7
Taro官方组件库——基础组件提供了一下几种组件

—Icon:图标
-Text:文本
—Progress:进度条
—RichText:富文本

三 类组件和功能组件

1
2
类组件:使用class声明,并继承Component,状态管理使用this.state和setState
功能组件:使用function的函数,状态管理使用Hooks

四 基础组件Text示例

4.1 功能组件示例(function声明)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { View, Text } from '@tarojs/components'
import { useLoad } from '@tarojs/taro'
import './index.scss'

export default function Index () {
useLoad(() => {
console.log('Page loaded.')
})
return (
<View className='index'>
<Text>Hello world!!!</Text>
</View>
)
}

4.2 类组件示例(class关键字)

1
2
3
4
5
6
7
8
9
10
11
12
13
import { View, Text } from '@tarojs/components'
import { Component, ReactNode } from 'react'
import './index.scss'

export default class Index extends Component {
render(){
return (
<View className='index'>
<Text>Hello world!!!</Text>
</View>
)
}
}

4.3 效果图(H5)

七 参考

  • Taro官网
  • Taro组件库—Text