javascript - Es 6 problem Import
PHP中文网
PHP中文网 2017-05-19 10:31:18
0
3
597
What is the difference between

Import * as xxx from 'Xxx ' and
Import xxx from 'xxx'
?
At the same time, in vuex, why can you use var xxx= require('Xxx ') instead of the second writing method, but not the first one?

PHP中文网
PHP中文网

认证0级讲师

reply all(3)
Ty80

First question:

In addition to specifying a certain output value to load, you can also use overall loading, that is, use an asterisk (*) to specify an object, and all output values ​​will be loaded on this object.

Here is onecircle.js文件,它输出两个方法areacircumference。

// circle.js

export function area(radius) {
  return Math.PI * radius * radius;
}

export function circumference(radius) {
  return 2 * Math.PI * radius;
}

Now, load this module.

// main.js

import { area, circumference } from './circle';

console.log('圆面积:' + area(4));
console.log('圆周长:' + circumference(14));

The above writing method is to specify the methods to be loaded one by one. The overall loading method is as follows.

import * as circle from './circle';

console.log('圆面积:' + circle.area(4));
console.log('圆周长:' + circle.circumference(14));

The ECMAScript6 book from Ruan Yifeng
I hope the poster can understand it

过去多啦不再A梦

You can read this article
http://es6.ruanyifeng.com/#do...

迷茫

The writing method of import is related to the export of the module you import

According to the picture above, import xxx from 'XXX' is to name the export default in XXX as xxx
in this module, and var xxx = require('XXX'); is also to name the export default in XXX in this module. The module is named xxx, so it can be replaced;
import * as xxx from 'XXX'; means that all exports in XXX are named xxx in this module, and there is export function A(){...} in XXX. You can use xxx.A() to reference.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template