React 'Refs'
2018-07-30 本文已影响0人
韦卓凡
ref 有两种 ref 方式
- ref = ''string" //string
- ref = {this.saveInputRef} //function
// lib/math.js
export function sum(x, y) {
return x + y;
}
export var pi = 3.141593;
var num = 3.141593;
// app.js
import * as math from "lib/math";
alert("2π = " + math.sum(math.pi, math.pi));
// otherApp.js
import {sum, pi} from "lib/math";
alert("2π = " + sum(pi, pi));
// Some additional features include export default and export *:
// lib/mathplusplus.js
export * from "lib/math";
export var e = 2.71828182846;
export default function(x) {
return Math.log(x);
}
一个文件只能有一个default
// app.js
import ln, {pi, e} from "lib/mathplusplus";
alert("2π = " + ln(e)*pi*2);
将default function 命名为 ln