Skip to content

Commit

Permalink
docs: update components Text's example code
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen-jj committed Mar 5, 2019
1 parent 553116b commit 788bde9
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions docs/components/base/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,44 @@ sidebar_label: Text
###### 示例:
```jsx
import Taro, { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
import { View, Text, Button } from '@tarojs/components'

export default class PageView extends Component {
constructor () {
super(...arguments)

this.state = {
contents = []
}
state = {
contents: [],
contentsLen: 0
}

add = e => {
const cot = this.state.contents
cot.push({text: 'hello world'})

this.setState(() => {
return {contents: cot}
add = () => {
this.setState(prev => {
const cot = prev.contents.slice()
cot.push({ text: 'hello world' })
return {
contents: cot,
contentsLen: cot.length
}
})
}

remove = e => {
const cot = this.state.contents
cot.pop()
this.setState(() => {
return {contents: cot}
remove = () => {
this.setState(prev => {
const cot = prev.contents.slice()
cot.pop()
return {
contents: cot,
contentsLen: cot.length
}
})
}

render () {
return (
<View className='container'>
{this.state.contents.map(item => {
return (
<Text>{item.text}</Text>
)
})}
{this.state.contents.map((item, index) => (
<Text key={index}>{item.text}</Text>
))}
<Button className='btn-max-w button_style' plain type='default' onClick={this.add}>add line</Button>
<Button className='btn-max-w button_style' plain type='default' disabled={this.state.contents.length ? false:true} onClick={this.remove}>remove line</Button>
<Button className='btn-max-w button_style' plain type='default' disabled={this.state.contentsLen ? false : true} onClick={this.remove}>remove line</Button>
</View>
)
}
Expand Down

0 comments on commit 788bde9

Please sign in to comment.