React 'Refs'

2018-07-30  本文已影响0人  韦卓凡

ref 有两种 ref 方式

  1. ref = ''string" //string
  2. 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

上一篇下一篇

猜你喜欢

热点阅读