jsx

JSX简介

匿名 (未验证) 提交于 2019-12-02 21:53:52
“JSX” JSX就是Javascript和XML结合的一种格式。 React发明了JSX,利用HTML语法来创建虚拟DOM。当遇到<,JSX就当HTML解析,遇到{就当JavaScript解析。 JSX,是一个 JavaScript 的语法扩展。JSX 可以很好地描述 UI 应该呈现出它应有交互的本质形式。 JSX将XML语法直接加入JS中,通过代码而非模板来高效的定义界面。之后JSX通过翻译器转换为纯JS再由浏览器执行。在实际开发中,JSX在产品打包阶段都已经编译成纯JavaScript,JSX的语法不会带来任何性能影响。另外,由于JSX只是一种语法,因此JavaScript的关键字class, for等也不能出现在XML中,而要如例子中所示,使用className, htmlFor代替,这和原生DOM在JavaScript中的创建也是一致的。JSX只是创建虚拟DOM的一种语法格式而已,除了用JSX,我们也可以用JS代码来创建虚拟DOM. “JSX表示对象” React.createElement() 1 const element = ( 2 <h1 className="greeting"> 3 Hello, world! 4 </h1> 5 );  等效 1 const element = React.createElement( 2 'h1', 3 {className

React入门-JSX和虚拟dom

匿名 (未验证) 提交于 2019-12-02 21:53:52
1.JSX理解 举例: const element = <h1>Hello, world!</h1>; 这被称为 JSX,是一个 JavaScript 的语法扩展。建议在 React 中配合使用 JSX,JSX 可以生成 React “元素”,而且JSX 可以很好地描述 UI 应该呈现出它应有交互的本质形式。JSX 可能会使人联想到模版语言,但它具有 JavaScript 的全部功能。 为什么用JSX? React 认为渲染逻辑本质上与其他 UI 逻辑内在耦合,比如,在 UI 中需要绑定处理事件、在某些时刻状态发生变化时需要通知到 UI,以及需要在 UI 中展示准备好的数据。 React 并没有采用将 标记与逻辑进行分离到不同文件 这种人为地分离方式,而是通过将二者共同存放在称之为“组件”的松散耦合单元之中,来实现 关注点分离 。 在 JSX 中嵌入表达式 name const name = 'Josh Perez'; const element = <h1>Hello, {name}</h1>; ReactDOM.render( element, document.getElementById('root') ); 2 + 2 , user.firstName formatName(user) formatName(user) <h1> function formatName

Vue之render渲染函数和JSX的应用

匿名 (未验证) 提交于 2019-12-02 21:53:52
模板的最大特点是扩展难度大,不易扩展。可能会造成逻辑冗余 <Level :type="1">哈哈</Level> <Level :type="2">哈哈</Level> <Level :type="3">哈哈</Level> Level组件需要对不同的type产生不同的标签 <template> <h1 v-if="type==1"> <slot></slot> </h1> <h2 v-else-if="type==2"> <slot></slot> </h2> <h3 v-else-if="type==3"> <slot></slot> </h3> </template> <script> export default { props: { type: { type: Number } } }; </script> 函数式组件没有模板,只允许提供render函数 export default { render(h) { return h("h" + this.type, {}, this.$slots.default); }, props: { type: { type: Number } } }; 复杂的逻辑变得非常简单 使用jsx会让代码看起来更加简洁易于读取 export default { render(h) { const tag = "h" + this.type;

After Effects / ExtendScript: Using libraries and importing .jsx files?

匆匆过客 提交于 2019-12-02 21:07:54
I am new to After Effects scripting but have much experience with JavaScript in the browser. How do I import .jsx files? Can I use js libraries such as underscore.js etc? What are some good resources for AE scripting? (Ideally infographics projects) To include a .jsx next to your script use: #include "includeme.jsx" EDIT 2: You can also include files using the following syntax: //@include "includeme.jsx" Which (IMHO) is the better way. It wont break a linter and is more javascript-ish. You can use plain old javascript (ES3 Syntax). If the libraries you include use some browser specific js

Setting state in function doesn't trigger a rerender

萝らか妹 提交于 2019-12-02 14:33:17
问题 I want to make a loading indicator on user login, but for some reason the JSX conditional element does not update: class LoginPage extends Component { constructor (props) { super(props) this.state = { waitingOnLogin: false, ... } this.handleLogin = this.handleLogin.bind(this) } handleLogin (event) { event.preventDefault() this.state.waitingOnLogin = true this.props.userActions.login(this.state.email, this.state.password) } render() { return ( <div className='up'> <form onSubmit={e => this

Need help on React Js

这一生的挚爱 提交于 2019-12-02 13:23:49
I am new to React Js and my code is not working. Please have a look below: This is my script file Main.jsx . This file is compiled by react and output is put in main.js file under 'dist' folder. var react = require("react"), reactDom = require("react-dom"); var myComponent = react.createClass({ render: function () { return <div><h4>I am rendered by react.</h4></div>; } }); reactDom.render(<myComponent />, document.getElementById("basicDiv")); It is Index.html <html> <head> <base href="./" /> <title>App title</title> <script src="node_modules/react/dist/react.js"></script> <script src="node

Setting state in function doesn't trigger a rerender

我只是一个虾纸丫 提交于 2019-12-02 12:31:16
I want to make a loading indicator on user login, but for some reason the JSX conditional element does not update: class LoginPage extends Component { constructor (props) { super(props) this.state = { waitingOnLogin: false, ... } this.handleLogin = this.handleLogin.bind(this) } handleLogin (event) { event.preventDefault() this.state.waitingOnLogin = true this.props.userActions.login(this.state.email, this.state.password) } render() { return ( <div className='up'> <form onSubmit={e => this.handleLogin(e)}> ... </form> {this.state.waitingOnLogin && <Spinner message='Logging you in'/>} // This

React Accessing a value from an array

六眼飞鱼酱① 提交于 2019-12-02 10:40:37
I have a form in React which dynamically adds new input elements. This seems to be working ok but I cant seem to access the input values as shown in this screenshot... I have tried the following console.log(this.state.telephone.name) and... console.log(this.state.telephone.tidx.name) where tidx is the unique key. Here is the constructor... constructor() { super(); this.state = { role: "Installer", name: "", telephoneType: [{ name: "" }], telephone: [{ name: "" }], tidx: "", emailType: [{ email: "" }], email: [{ email: "" }], eidx: "", notes: "" }; } and this is my function to handle the input

06Babel

放肆的年华 提交于 2019-12-02 05:57:11
感悟 把webpack得入口和出口地址进行变更,同时devServer里面contentBase得地址也要变更,这个地址是本地服务器所加载得页面所在得目录 devServer: { contentBase: "./public",//本地服务器所加载的页面所在的目录 } webpack学习:如今这个目录下得webpack.config.js得配置如下 module.exports = { entry: __dirname + "/06Babel/app/main.js", output: { path: __dirname + "/06Babel/public", filename: "bundle.js" }, devtool:"eval-source-map", devServer: { contentBase: "./06Babel/public", //本地服务器所加载的页面所在的目录 historyApiFallback:true,//不跳转 inline:true//实时刷新 } } 新内容:Babel Babel其实是一个编译JavaScript的平台,它可以编译代码帮你达到以下目的: 让你能使用最新的JavaScript代码(ES6,ES7...),而不用管新标准是否被当前使用的浏览器完全支持; 让你能使用基于JavaScript进行了拓展的语言

Undefined is not a function near _reactNavigation.StackNavigator

[亡魂溺海] 提交于 2019-12-02 02:33:48
I want to setup a React Native app with a side menu and a tab menu at the same time. I was following this tutorial. My code . I get the error: undefined is not a function (near '...(0 , _reactNavigation.TabNavigator)...') Which you can see here: Preview of some of the files: App.js import React from 'react'; import { Drawer } from './src/navigators'; export default class App extends React.Component { render() { return ( <Drawer /> ); } } navigators.js import React, { Component } from 'react'; import { StyleSheet, Text, View } from 'react-native'; // Navigators import { DrawerNavigator,