This article will talk about the main differences between Taro development and native mini program development. I hope it will help students who master native mini program development but don't know much about Taro to migrate quickly.
When using React/Vue, global variables are recommended to be managed with state management tools like React Redux, Vuex.
And sometimes some projects converted from native mini program will mount global variables to
app and use
getApp() to get them. It is more expensive to convert to React Redux, Vuex and other state management methods.
This writing style can therefore be made compatible using the
taroGlobalData property of the entry object.
In native mini program development, when calling some APIs in custom components, such as
createSelectorQuery, etc., you need to pass in
this that points to the custom component itself, which is tentatively called
However, Taro 3 uses the
<template> tag for rendering and does not normally use custom components, so you don't need to pass it in.
There are only two cases where a custom component will be used, and you need to pass
scope correctly, otherwise such API calls will fail.
For mini program without recursion support (platform-plugin-template#recursive vs. non-recursive template) (WeChat, QQ, Jingdong mini program, etc.), when the page element nesting level exceeds a certain number of levels (default is 16, which can be modified by configuring baseLevel), a custom component will be created to assist recursion.
scope of this custom component is not exposed to the developer, so it needs to be wrapped with a
<CustomWrapper> component if the hierarchy is too deep and you need to call this API.
Related discussion #9357。
<CustomWrapper> It is often used to optimize update performance. It is essentially an mini program custom component.
dataset concept for mini program is partially implemented in Taro, for details see.