【Taro】实战问题

Posted by ARTROY on 2019-05-27

实战总结

1、当有方法包裹的时候, 在 Taro 转化小程序过程中,首先先将 item 进行声明 ,可是有与这个 item 没有个默认值,解决办法 给整个组件一个默认值 Topic.defaultProps
报错:
error
解决办法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Topic extends Component {
// 跳转至详情
goToDetail() {
Taro.navigateTo({url: '/pages/detail/detail'})
}
render () {
let { item } = this.props;
return (
<View className='topic-item' onClick={this.goToDetail.bind(this)}>
<Image className='topic-img' src={item.author ? item.author.avatar_url : ''} alt={item.author ? item.author.loginname : ''} />
<View className='topic-right'>
<View className='topic-top'>
<Text className='topic-title'>{item.title}</Text>
</View>
<View className='topic-bottom'>
<Text >{item.reply_count}/{item.visit_count}</Text>
<Text>{item.create_at ? myTimeToLocal(item.create_at) : ''}</Text>
</View>
</View>
</View>
)
}
}

// 解决办法
Topic.defaultProps = {
item: {}
}

2、发布 微信小程序
打开project.config.json 文件修改 AppID, 并在开发小程序工具中点击上传,打开“微信公众平台” --> 点击 “首页” --> 点击“发布”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"miniprogramRoot": "dist/",
"projectname": "APP",
"description": "APP Web",
"appid": "wxea....11", // 添加微信小程序AppID
"setting": {
"urlCheck": true,
"es6": false,
"postcss": false,
"minified": false
},
"compileType": "miniprogram",
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {}
}


支付宝打赏 微信打赏

欣赏此文,打赏一下



-->