当前位置:网站首页>Applet framework taro
Applet framework taro
2022-07-05 10:48:00 【Code Bruce Lee】
Taro
1、 Introduce
It's following React Multi terminal development solution of syntax specification
Can write a set of code , Re pass Taro The compiler of , Compile the code separately, which can be on different ends ( Wechat applet 、H5、RN) Running code
2、 characteristic
2.1 React Grammar style
with React Consistent idea of componentization , Life cycle and React bring into correspondence with , Support at the same time JSX grammar
2.2 Quickly develop wechat apps
Support use npm / yarn Third party installation management relies on
Support ES6/7/8 Even newer ES standard
Support CSS Precompiler
Support Redux Conduct status management
Applet API Optimize
2.3 Support multi terminal development and transformation
Can support conversion to Wechat applet as well as H5 End
3、 Environment building
$ cnpm i -g @tarojs/cli
$ taro init myApp01
4、 Compile using the
4.1 Wechat applet
$ npm run dev:weapp
$ npm run build:weapp
4.2 Baidu applet
$ npm run dev:swan
$ npm run build:swan
4.3 Alipay applet
$ npm run dev:alipay
$ npm run build:alipay
4.4 H5
$ npm run dev:h5
$ npm run build:h5
4.5 React Native
$ npm run dev:rn
5、 form
https://nervjs.github.io/taro/docs/composition.html
6、 matters needing attention
6.1 Applet development tool settings
You need to set the shutdown ES6 turn ES5 function , Error may be reported when opening
You need to set the style auto completion when uploading code is turned off , Error may be reported when opening
You need to set to turn off code compression uploading , Error may be reported when opening
7、 Project directory structure
├── dist 【 Compile results directory 】
├── config 【 The configuration directory 】
| ├── dev.js 【 Configuration at development time 】
| ├── index.js 【 The default configuration 】
| └── prod.js 【 Configure when packaging 】
├── src 【 Source directory 】
| ├── pages 【 Page file directory 】
| | ├── index 【index Page directory 】
| | | ├── index.js 【index Page logic 】
| | | └── index.css 【index Page style 】
| ├── app.css 【 Project general style 】
| └── app.js 【 Project entry documents 】
└── package.json
7.1 Entrance file app.js
// -> The entry file is also react The style of writing
// -> Reference dependency required @tarojs/taro, This is a Taro The basic framework of the scheme , Here we inherit Component Component base class
import Taro, { Component } from ‘@tarojs/taro’
import Index from ‘./pages/index’
import ‘./app.less’
class App extends Component {
// -> The configuration here mainly refers to the global configuration of wechat applet , When compiling into an applet , This part of the configuration will be separated into app.json, And compiled into other end , It will also have other functions
config = {
pages: [
‘pages/index/index’
],
window: {
backgroundTextStyle: ‘light’,
navigationBarBackgroundColor: ‘#fff’,
navigationBarTitleText: ‘WeChat’,
navigationBarTextStyle: ‘black’
}
}
// -> The entry file is inherited from Component Component base class , It also has a component lifecycle , But because of the particularity of the entry file , His life cycle is not complete
componentWillMount () {
// effect -> The program is loaded
// explain -> In wechat applet, this life cycle method corresponds to app Of onLaunch
}
componentDidMount () {
// effect -> The program is loaded
// explain -> In wechat applet, this life cycle method corresponds to app Of onLaunch, stay componentWillMount After execution
}
componentDidShow () {
// effect -> The program is displayed
// explain -> In wechat applet, this life cycle method corresponds to onShow, stay H5 It is also implemented in
}
componentDidHide () {
// effect -> Program is hidden
// explain -> In wechat applet, this life cycle method corresponds to onHide, stay H5 It is also implemented in
}
componentDidCatchError () {
// effect -> Error listening function
// explain -> In wechat applet, this life cycle method corresponds to onError
}
componentDidNotFound () {
// effect -> There is no listener function on the page
// explain -> In wechat applet, this life cycle method corresponds to onPageNotFound
}
// stay App Class render() Function doesn't work
// Do not modify this function
render () {
return (
)
}
}
Taro.render(, document.getElementById(‘app’))
// Be careful
// 1. Wechat applet onLaunch Usually with a parameter options, stay Taro You can pass in all life cycles and common event methods this.$router.params Access to the , It also applies to other ends
// 2. The entry file needs to contain a render Method , Generally return to the first page of the program , But it is worth noting that it is not in the entry file render Method to write logic and reference other pages 、 Components , Because compile time render The content of the method will be directly replaced , Your logic code won't work .
边栏推荐
- Network security of secondary vocational group 2021 Jiangsu provincial competition 5 sets of topics environment + analysis of all necessary private messages I
- [vite] 1371 - develop vite plug-ins by hand
- 数据库中的范式:第一范式,第二范式,第三范式
- 基于昇腾AI丨爱笔智能推出银行网点数字化解决方案,实现从总部到网点的信息数字化全覆盖
- [paper reading] ckan: collaborative knowledge aware autonomous network for adviser systems
- 【DNS】“Can‘t resolve host“ as non-root user, but works fine as root
- 变量///
- go语言学习笔记-初识Go语言
- App各大应用商店/应用市场网址汇总
- A usage example that can be compatible with various database transactions
猜你喜欢
随机推荐
ModuleNotFoundError: No module named ‘scrapy‘ 终极解决方式
Pull up loading principle
[observation] with the rise of the "independent station" model of cross-border e-commerce, how to seize the next dividend explosion era?
Based on shengteng AI Aibi intelligence, we launched a digital solution for bank outlets to achieve full digital coverage of information from headquarters to outlets
非技術部門,如何參與 DevOps?
2022年危险化学品生产单位安全生产管理人员特种作业证考试题库模拟考试平台操作
重磅:国产IDE发布,由阿里研发,完全开源!
iframe
赛克瑞浦动力电池首台产品正式下线
九、磁盘管理
数据库中的范式:第一范式,第二范式,第三范式
【观察】跨境电商“独立站”模式崛起,如何抓住下一个红利爆发时代?
[可能没有默认的字体]Warning: imagettfbbox() [function.imagettfbbox]: Invalid font filename……
Web Components
Use bat command to launch common browsers with one click
How can gbase 8C database view the login information of the login user, such as the date, time and IP of the last login authentication?
C语言活期储蓄账户管理系统
中职组网络安全2021年江苏省省赛题目5套题目环境+解析全有需要的私信我
字符串、、
非技术部门,如何参与 DevOps?