当前位置:网站首页>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 .
边栏推荐
- 手机厂商“互卷”之年:“机海战术”失灵,“慢节奏”打法崛起
- NAS and San
- 爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
- 第五届 Polkadot Hackathon 创业大赛全程回顾,获胜项目揭秘!
- LDAP overview
- 2022年危险化学品生产单位安全生产管理人员特种作业证考试题库模拟考试平台操作
- Implement the rising edge in C #, and simulate the PLC environment to verify the difference between if statement using the rising edge and not using the rising edge
- Blockbuster: the domestic IDE is released, developed by Alibaba, and is completely open source!
- Go language-1-development environment configuration
- 【SWT组件】内容滚动组件 ScrolledComposite
猜你喜欢

"Everyday Mathematics" serial 58: February 27

Ad20 make logo

Some understandings of heterogeneous graphs in DGL and the usage of heterogeneous graph convolution heterographconv

重磅:国产IDE发布,由阿里研发,完全开源!

基于昇腾AI丨以萨技术推出视频图像全目标结构化解决方案,达到业界领先水平

The first product of Sepp power battery was officially launched

Go语言-1-开发环境配置

谈谈对Flink框架中容错机制及状态的一致性的理解

在C# 中实现上升沿,并模仿PLC环境验证 If 语句使用上升沿和不使用上升沿的不同

Learning notes 5 - high precision map solution
随机推荐
想请教一下,十大券商有哪些?在线开户是安全么?
Some understandings of heterogeneous graphs in DGL and the usage of heterogeneous graph convolution heterographconv
Learning note 4 -- Key Technologies of high-precision map (Part 2)
在C# 中实现上升沿,并模仿PLC环境验证 If 语句使用上升沿和不使用上升沿的不同
A usage example that can be compatible with various database transactions
GO项目实战 — Gorm格式化时间字段
LDAP概述
关于vray 5.2的使用(自研笔记)
非技术部门,如何参与 DevOps?
Lazy loading scheme of pictures
数组、、、
Comparative learning in the period of "arms race"
Pull up loading principle
关于vray 5.2的使用(自研笔记)(二)
Go language-1-development environment configuration
正则表达式
Common functions of go-2-vim IDE
Buried point 111
Crawler (9) - scrape framework (1) | scrape asynchronous web crawler framework
小程序框架Taro