React 是通过require引入进来的。如图:
方括号内部的各种元素也是通过require方式引进来的。
那么第一幅图中的语句是什么意思呢?
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
In ES5, if you use the CommonJS standard, the introduction of the React package is basically done through require. The code is similar to this:
//ES5 var React = require("react-native"); var { Image, Text, PropTypes } = React; //引用不同的React Native组件
In ES6, the import writing method is more standard
//ES6 import React, { Image, Text, PropTypes } from 'react-native';
Note that in React Native, import will not work properly until 0.12+.
Figure 1 is the writing method of ES6, destructuring assignment, simple usage: Array: var [a, b, c] = [1, 2, 3];var [a, b, c] = [1, 2, 3];对象:var { foo, bar } = { foo: "aaa", bar: "bbb" };Object:
var [a, b, c] = [1, 2, 3];
var { foo, bar } = { foo: "aaa", bar: "bbb" };
var test = { foo: "aaa", bar: "bbb" }; var { foo, bar } = test; console.log(foo) // "aaa"
In ES5, if you use the CommonJS standard, the introduction of the React package is basically done through require. The code is similar to this:
In ES6, the import writing method is more standard
Note that in React Native, import will not work properly until 0.12+.
Figure 1 is the writing method of ES6, destructuring assignment, simple usage:
Array:
var [a, b, c] = [1, 2, 3];
var [a, b, c] = [1, 2, 3];
对象:
var { foo, bar } = { foo: "aaa", bar: "bbb" };
Object:var { foo, bar } = { foo: "aaa", bar: "bbb" };
🎜