vue-CommonJS

commonJs导入导出

导出:

var flag = true
function sum(a,b){
     
  return a+b;
}
module.exports = {
     
  flag: flag,
  sum: sum
}

导入

var {
     flag,sum} = require('./01.js')
console.log(sum(1, 2));

ES模块化的导入和导出

export {
     
  flag,sum
}
import {
     flag,sum} from './01.js'

方式二

export var isok = false
export function sum(a,b){
     
  return a+b;
}

export class Person{
     
  constructor(name,age) {
     
    this.name = name;
    this.age = age;
  }
  run(){
     
    console.log(this.name + ' running');
  }
const p = new Person();
p.run();

export default

export default address = '北京' 只能有一个
import addr from './01.js' 不需要大括号
import * as aaa from './01.js

你可能感兴趣的:(vue,vue)