jsx

React学习记录1.2.2——JSX

依然范特西╮ 提交于 2019-12-17 01:38:58
JSX语法——数组 将数组映射到dom,这里给出两种不同的写法。一种是普通的数组,一种是用jsx语法生成的数组。 注意点都写在注释中 < body > < div id = "arr0" > < / div > < div id = "arr1" > < / div > < / body > < script type = "text/babel" > //写法1 const arr = [ { name : '商品A' , num : 0 } , { name : '商品B' , num : 1 } ] ; let Test0 = React . createClass ( { render ( ) { return < span > { arr . map ( ( item , i ) => { console . log ( item ) ; return < div key = { i } attr = { i + 1 } > 名称 { item . name } - 数量 { item . num } < / div > ; // vue和react在新版中,都增加了key,用于更新时对虚拟dom的比对。 //注意,这里的key值不能绑定对象,否则只能遍历出一项 } ) } < / span > } } ) ReactDOM . render ( < Test0 / >

React学习记录1.2——JSX

心不动则不痛 提交于 2019-12-17 01:21:05
JSX语法规则 这里先说几条基本的,有些细节部分会穿插在示例中。 jsx必须依赖react环境 不使用双引号 在jsx中运行js代码 <h1>{javascript code}</h1> 组件 类名必须以大写字母开头,驼峰命名 使用React.createClass()方法来创建 每个组件类 必须实现自己的 render方法,返回值true false 或组件模板 组件类只能包含一个顶层标签 JSX语法示例——hello world < body > < div id = "main_0" > < / div > < div id = "main_1" > < / div > < script type = "text/babel" > let Main0 = React . createClass ( { render : ( ) => { return < h1 > Hellow World < / h1 > } } ) ; let Main1 = React . createClass ( { render : ( ) => { return ( < h2 > I am < / h2 > < br / > < p > react < / p > ) } } ) ; ReactDOM . render ( < Main0 / > , document .

剥开比原看代码17:比原是如何显示交易的详细信息的?

我怕爱的太早我们不能终老 提交于 2019-12-16 10:19:36
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 作者:freewind 比原项目仓库: Github地址: https://github.com/Bytom/bytom Gitee地址: https://gitee.com/BytomBlockchain/bytom 在上上篇文章里,我们还剩下一个小问题没有解决,即前端是如何显示一个交易的详细信息的。 先看对应的图片: 这个图片由于太长,分成了两个,实际上可以看作一个。 那么这个页面是怎么来的呢?这是在前面以列表的方式显示交易摘要信息后,可以点击摘要信息右上角的“查看详情”链接打开。 那我们在本文看一下,比原是如何显示这个交易的详细信息的。 由于它分成了前后两端,那么我们跟以前一样,把它再分成两个小问题: 前端是怎么向后台发送请求,并显示数据的 后端是如何拿到相应的数据发送给前台的 需要说明的是,这个表格中包含了很多信息,但是我们在本文并不打算去解释。因为能看懂的一看就能明白,看不懂的就需要准确的了解了比原的核心之后才能解释清楚,而这一块等到我们晚点再专门研究。 前端是怎么向后台发送请求,并显示数据的 首先我们看一下显示交易详细信息页面的路由path是多少。当我们把鼠标放在交易摘要页面右上角的“查看详情”时,会发现url类似于: http://localhost:9888/dashboard

Vue与react异同

纵饮孤独 提交于 2019-12-15 22:42:19
Vue使用模板系统而不是JSX,使其对现有应用的升级更加容易。 相似之处 1.他们都使用了一种叫'Virtual DOM'的东西【虚拟DOM,DOM树的虚拟表现】 2.组件化 -- 模块 vue >> . vue 文件 react >> jsx JavaScript与JSX被写入同一个组件文件中 3.Props React和Vue都有'props'的概念,这是properties的简写。props在组件中是一个特殊的属性,允许父组件往子组件传送数据。 4.构建工具 React和Vue都有自己的构建工具,你可以使用它快速搭建开发环境。React可以使用Create React App (CRA),而Vue对应的则是vue-cli。 · 主要区别 1.模板 vs JSX Vue鼓励你去写近似常规HTML的模板。 React推荐你所有的模板通用JavaScript的语法扩展——JSX书写 2.状态管理 vs 对象属性 state状态是(React)关键的概念 对象在React应用中是不可变的 在Vue中,state对象并不是必须的,数据由data属性在Vue对象中进行管理。 参考文档: http://caibaojian.com/vue-vs-react.html 来源: CSDN 作者: 做个有准备的人 链接: https://blog.csdn.net/u011565547

Load .jsx files with webpack

谁都会走 提交于 2019-12-14 03:53:28
问题 I have a problem with loading .jsx files using webpack . I have this webpack.config.js : var webpack = require('webpack'); module.exports = { entry: "./static/js/storage/src/index.js", output: { path: './static/js/storage/public/', publicPath: "public/", filename: "bundle.js" }, resolve: { extensions: ['', '.js', '.jsx'] }, module: { loaders: [ { test: /\.js$/, loader: "babel-loader", exclude: [/node_modules/, /public/], query: { plugins: ['transform-runtime'], presets: ['es2015', 'stage-0',

React - Slide fixed navbar up on scroll down and slide down on scroll up

北慕城南 提交于 2019-12-14 03:42:44
问题 tl;dr Scroll down for the solution that worked for me! How to implement a slide up and down on a fixed navbar in react? What is the better approach using refs or using the componentDidMount lifecycle hook? hideNav = (navbar) => { const hide = () => { let lastScrollTop = 0; const currentScrollTop = navbar.scrollTop; // scroll down if (currentScrollTop > lastScrollTop) { navbar.classList.add('hidden'); } else { // scroll up navbar.classList.remove('hidden'); } lastScrollTop = currentScrollTop;

Loop inside of a loop, in React JSX

天涯浪子 提交于 2019-12-14 02:09:22
问题 I am trying to render in react, jsx, a loop inside of a loop Like bellow: {this.state.ans.map(function(item) { return ( {this.state.quest.map( function(item1) {return (item1)} )} {item} ) })} This does not work any other suggestions 回答1: You forgot the wrapping div in your first map statement: render() { return ( <div> {this.state.ans.map(item => <div> // this div was missing {this.state.quest.map(quest => quest)} {item} </div> )} </div> ) } 回答2: Try it like this: render(){ return ( . . .

Cannot store arrow function in let/var in React Component

孤街醉人 提交于 2019-12-13 21:34:45
问题 I have a component in react defined by extends React.Component . Inside it, along with the render method, is: constructor(props, context) { super(props, context); this.state = { open: false, }; } handleClose = () => { //this works this.setState({open: false}); }; handleOpen = () => { //this works this.setState({open: true}); }; let empty = () => {}; // does not work, error Parsing error: Unexpected token I seem to get an unexpected token error if I prefix any of the arrow functions with let

Add edit fields on table row on click in reactjs without using react-table library

笑着哭i 提交于 2019-12-13 18:34:08
问题 How to change a particular row that is clicked in JSX table to change to input editable row without using any libraries such as react-table? <table className="table-data"> <tbody> <tr> <th>Name</th> <th>Age</th> <th>Class</th> <th>Section</th> </tr> {this.state.students.map((item,key) => {return <Fragment key={key}> <tr key={key} onClick={()=> {this.setState({clientIsEditing:true},this.edit(key,item))}}> <td>{item[1]}</td> <td>{item[2]}</td> <td>{item[3]}</td> <td>{item[4]}</td> </tr> <

How to create your own babel processor alternative to `React`

删除回忆录丶 提交于 2019-12-13 16:40:44
问题 When you use JSX in a JS file, you have to import React or else the generated code won't compile. This is because this: import React from 'react' import ReactDOM from 'react-dom' function Foo() { return 'hello world' } ReactDOM.render(<Foo/>, document.body) Becomes: import React from 'react' import ReactDOM from 'react-dom' function Foo() { return 'hello world' } ReactDOM.render(React.createElement(Foo), document.body) So the React in React.createElement is getting generated by some babel or