Taro学习记录

1.使用taro每个页面都有一个 config配置,配置参考自微信小程序的页面配置。组件不能有config
在这里插入图片描述
2.页面的声明周期:
componentWillMount
componentDidMount
shoulidComponentUpdate
componentWillUpdate
componentDidUpdate
componentWillUnmount
componentDidShow
componentDidHide
3.在taro中可以通过任何一个生命周期或函数通过this.$router.params来访问当前页面的路径和query
在这里插入图片描述
4.小程序中的一些专属方法
方法 作用
onPullDownRefresh 页面相关事件处理函数–监听用户下拉动作
onReachBottom 页面上拉触底事件的处理函数
onShareAppMessage 用户点击右上角转发
onPageScroll 页面滚动触发事件的处理函数
onTabItemTap 当前是 tab 页时,点击 tab 时触发
componentWillPreload 预加载, 只在微信小程序中可用
5、组件可以统一放到 src/components 目录下,与页面解构一样,每一个组件包含一个js文件和样式文件。组件没有config,只有页面才有,组件多一个componentWillReceiveProps生命周期函数。
在这里插入图片描述
在这里插入图片描述

6、文件命名规范: js文件用小写字母,多个字母用_分隔。组件用大驼峰命名:ReservationCard.jsx。组件文件后缀一般用.jsx。
7、taro中字符串统一用单引号
8、taro中的jsx不能使用html标签
9、taro中数据请求尽量写在componentWillMount
10、不能在componentWillUpdate/componentDidUpdate/render 中调用 this.setState
11、组件最好定义 defaultProps
12、在map映射中尽量使用 三元表达式,避免if语句
13、taro页面跳转,路径必须和入口app.js中配置的一致。

// 跳转到目的页面,打开新页面
Taro.navigateTo({
  url: '/pages/detail/index'
})

// 跳转到目的页面,在当前页面打开
Taro.redirectTo({
  url: '/pages/detail/index'
})

14、路由传参通过追击url来实现,获取传参通过this.$router.params
在这里插入图片描述
在这里插入图片描述

15、页面尺寸单位写px或百分比,就是量多少写多少。taro会自动转成rpx或rem。taro默认转换750。如果切换在config>index.js designWidth处修改配偶。还支持640、828.
在这里插入图片描述

16、引入文件
在这里插入图片描述

17、taro默认将10kb以下静态资源转为base64。
在这里插入图片描述

18、taro中阻止事件冒泡使用stopPropagation
19、任何组件的事件传递都要以 on 开头
在这里插入图片描述
在这里插入图片描述

20、组件中最好定义defaultProps
在这里插入图片描述

Taro.watch 是一个用于构建小程序的开发工具,它可以实时监测文件的变化并自动重新构建项目。在使用 Taro 开发工具时,你可以通过以下命令启用实时监测功能: ``` taro build --type weapp --watch ``` 或者使用 npx 工具: ``` npx taro build --type weapp --watch ``` 这样,当你对项目中的文件进行修改时,Taro.watch 会自动重新构建项目,使你能够实时查看修改后的效果。 除此之外,Taro 还建议使用 px 或百分比 % 作为尺寸单位,并将设计稿的宽度设置为 750px。如果需要修改这些配置,你可以在配置文件中的 designWidth 属性进行修改。 对于页面跳转操作,你可以在入口文件的 config 配置中指定好页面路径,然后在代码中使用 Taro 提供的 API 来进行页面跳转操作。例如,你可以使用 Taro.navigateTo({ url: '/pages/path/to/name' }) 来跳转到目的页面,并在新页面中打开,或者使用 Taro.redirectTo({ url: '/pages/path/to/name' }) 在当前页面打开目的页面。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [taro-ui-demo:非 Taro UI 官网示例代码](https://download.csdn.net/download/weixin_42164685/18277852)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Taro 学习笔记](https://blog.csdn.net/weixin_33970449/article/details/88002889)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [关于Taro的那些事儿+遇到的一些问题汇总,持续更新ing](https://blog.csdn.net/weixin_44987713/article/details/115542637)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值