知识点1: 箭头函数
无参
function myConsole1 () { console.log(666)}let myConsole2 = function () { console.log(777)}// 箭头函数let myConsole3 = () => { console.log(888)}// 箭头函数,函数体只有一行时可以省略{}let myConsole4 = () => console.log(999)export {myConsole1, myConsole2, myConsole3, myConsole4}
单参
let myConsole1 = function (value) { console.log(value)}// 箭头函数let myConsole2 = (value) => { console.log(value)}export {myConsole1, myConsole2}
多参
let myCount1 = function (num1, num2) { let count = num1 + num2 console.log(count)}// 箭头函数let myCount2 = (num1, num2) => { let count = num1 + num2 console.log(count)}export {myCount1, myCount2}
返回对象
hello.js
function obj1 () { return ({name: 'Jack1', age: 31})}let obj2 = function () { return ({name: 'Jack2', age: 32})}// 箭头函数let obj3 = xxx => { return ({name: 'Jack3', age: 33})}export {obj1, obj2, obj3}
hello.vue
import {obj1, obj2, obj3} from '../../util/es6Test/hello'export default { mounted () { console.log(obj1().name, obj1().age) console.log(obj2().name, obj2().age) console.log(obj3().name, obj3().age) }}