diff --git a/docs/components/base/text.md b/docs/components/base/text.md index 02fa7367d744..e47d1ea8bdc8 100755 --- a/docs/components/base/text.md +++ b/docs/components/base/text.md @@ -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 ( - {this.state.contents.map(item => { - return ( - {item.text} - ) - })} + {this.state.contents.map((item, index) => ( + {item.text} + ))} - + ) }