本文总结了 vue react 和小程序三者间写法的区别, 希望对学习中的同学有帮助.
1. 标签内属性:
- vue:
- :key = "index" (直接字符串)
- react:
- key={
- index
- } (单括号)
小程序:
key="{{index}}" (字符串内双括号)
2. 绑定事件
- vue:
- @click="clickFuc" (字符串)
- react:
- onClick={
- clickFuc
- } (单括号)
小程序:
onTap="clickFuc" (字符串)
3. 动态内联 style 和 class
- vue:
- :style="{height: xx> 0?'300px':' '}"
- :class="{firstImg: index === 0}"
- react:
- style={
- {
- display: (index === this.state.currentIndex) ? 'block': 'none'
- }
- }
- className={
- `red ${index === this.state.currentIndex ?'active' : null }`
- }
小程序:
- style="display: {{ num ===3?'block':'none'}}"
- class="red {{num==3?'cur':' '}}"
4. 数据修改
- Vue
- this.data1 = 123;
- React
- this.setState({
- data1: 123
- });
小程序
- this.setData({
- data1: 123
- });
本文来自 React 答疑 https://www.html.cn/qa/react/ 栏目, 欢迎学习!
来源: http://www.css88.com/qa/react/14337.html