模版字符串

let name = 'wangjianfeng'
console.log(`hello ${name}`)
//输出 hello wangjianfeng

//多行
let name = 'wangjianfeng'
let content = `
    hello ${name}
    good
`

默认参数

function log(msg, type = 'log'){
    console.log(msg, type)
}
log('hello')
//hello log

箭头函数

let arr = [1, 2, 3,'a', 'b']
arr.forEach(function (item, i){
    arr[i] = item + item
} )
console.log(arr)
//[2, 4, 6, "aa", "bb"]

import和export

import 用于引入模块,export用于定义模块后导出模块

解构赋值

//数组
let [a, b, c] = [1, 2, 3]
//对象
let {a, b} = {a: 'aaa', b: 'bbb'}
//函数的参数
function add([x, y]){
    return x+ y;
}
add([1,2])
//3

扩展运算符

const a = [1, 2]
const b = [...a, 3]
console.log(b)
//[1, 2, 3]

onst a = {x: 1, y: 2}
const b = {...a,z:3}
console.log(b)
//{x: 1, y: 2, z: 3}

Promise

//基本用法
var promist = new Promise(function(resolve, reject){
    //.....
    //....
    if(true/*异步操作成功*/){
      resolve(value)
    }else {
        reject(error)
    }
})
//例子
fetch('getSome', {
    userID: this.userID
}).then(res =>{
    console.log(res)
}).catch(err =>{
    this.$message({
        message: err.error ? err.error : '请求失败,请重试',
        type: 'warning'
    })
})

你的闲暇往往定你的终身

标签云

友情链接