React(3) --react绑定属性
react绑定属性
/*
react绑定属性注意: class要换成className for要换成 htmlFor style: <div style={{"color":'red'}}>我是一个红的的 div 行内样式</div> 其他的属性和以前写法是一样的 */
//组件名称首字母大写、组件类名称首字母大写
class Home extends React.Component{
// 子类必须在constructor方法中调用super方法,否则新建实例时会报错。这是因为子类没有自己的this对象,而是继承父类的this对象,然后对其进行加工。如果不调用super方法,子类就得不到this对象
constructor(props){
super(props); //固定写法 this.state={ msg:'我是一个home组件',
title:'我是一个title',
color:'red',
style:{ color:'red',
fontSize:'40px'
}
}
}
render(){
return(
<div> //所有的模板要被一个根节点div包含起来
<h2>{this.state.msg}</h2> <div title="">我是一个div</div> <br />
<div title={this.state.title}>我是一个div</div> <br /> <div id="box" className='red'>我是一个红的的div---id</div> <br /> <div className={this.state.color}>我是一个红的的div </div> <br /> <label htmlFor="name">姓名</label> <input id="name" /> <br />
<br />
<div style={{"color":'red'}}>我是一个红的的 div 行内样式</div> <br />
<br />
<div style={this.state.style}>我是一个红的的 div 行内样式</div> </div>
) }
}
export default Home;
React(3) --react绑定属性的更多相关文章
- React对比Vue(02 绑定属性,图片引入,数组循环等对比)
import React, { Component } from 'react'; import girl from '../assets/images/1.jpg' //这个是全局的不要this.s ...
- React的双向绑定
以前对于双向绑定概念来自于Angular.js,现在我用我感兴趣的react.js来实现这样的方式.有2种方式分析,1:不用插件,2:用插件 (引入react.js操作省略...) 不用插件: 先创建 ...
- react实现双向绑定
双向绑定功能是在项目中比较常见的一个需求,传统的js实现方式是添加监听函数的方式,Vue框架实现很简单,因为它本身就是基于双向绑定实现的,接下来我将讲解一下如何使用react实现双向绑定的功能是 首先 ...
- React系列之--props属性
版权声明:本文为博主原创文章,未经博主允许不得转载. PS:转载请注明出处作者:TigerChain地址:http://www.jianshu.com/p/fa81cebac3ef本文出自TigerC ...
- React 与 React Native 底层共识:React 是什么
此系列文章将整合我的 React 视频教程与 React Native 书籍中的精华部分,给大家介绍 React 与 React Native 结合学习的方法,此小节主要介绍 React 的底层原理与 ...
- 一次掌握 React 与 React Native 两个框架
此系列文章将整合我的 React 视频教程与 React Native 书籍中的精华部分,给大家介绍 React 与 React Native 结合学习的方法. 1. 软件开发语言与框架的学习本质 我 ...
- React、React Native面试题
1.React Native相对于原生的ios和Android有哪些优势. react native一套代码可以开发出跨平台app, 减少了人力.节省了时间.避免了 iOS 与 Android 版本发 ...
- 用react-service做状态管理,适用于react、react native
转载自:https://blog.csdn.net/wo_shi_ma_nong/article/details/100713151 . react-service是一个非常简单的用来在react.r ...
- React的React Native
React的React Native React无疑是今年最火的前端框架,github上的star直逼30,000,基于React的React Native的star也直逼20,000.有了React ...
随机推荐
- 【leetcode】449. Serialize and Deserialize BST
题目如下: Serialization is the process of converting a data structure or object into a sequence of bits ...
- 一波儿networkx 读写edgelist,给节点加attribute的操作
一波儿networkx 读写edgelist,给节点加attribute的操作 read more: nx official: Reading and writing graphs import nu ...
- js事件循环机制
本文参考链接:https://www.jianshu.com/p/cf47bc0bf2ab 一.先搞懂两个东西:堆和栈 栈由操作系统自动分配释放,用于存放函数的参数值.局部变量等一些基本的数据类型,其 ...
- linux运维、架构之路-Zabbix自动化
一.Zabbix自定义监控 web01客户端修改/etc/zabbix/zabbix_agentd.conf [root@m01 tools]# echo "UserParameter=lo ...
- 【easyui-combobox】下拉菜单自动补全功能,Ajax获取远程数据源
这个是针对easyUI的下拉菜单使用的,Ajax获取远程数据源 HTML 页面 <input id="uname" name="uname" class= ...
- Codeforecs Round #425 D Misha, Grisha and Underground (倍增LCA)
D. Misha, Grisha and Underground time limit per test 2 seconds memory limit per test 256 megabytes i ...
- ruby的实例变量
class Box def initialize(w,h) @width,@height=w,h end def getArea @height*@width end end class BigBox ...
- 131、TensorFlow保存模型
# tf.train.Saver类提供了保存和恢复模型的方法 # tf.train.Saver的构造函数 提供了save和恢复的参数选项 # Saver对象提供了方法来运行这些计算节点,制定了写和读的 ...
- Java常用工具——java集合
一.ArrayList package com.imooc.set; import java.util.ArrayList; import java.util.List; public class A ...
- maven 依赖调解
项目A有两条依赖关系 A->B->C->X(1.0),A->D->X(2.0) ,X是A的传递性依赖,但是两条路径上有两个版本的依赖,会选择哪个呢? maven 依赖调 ...