vue常用的ES6语法--内置对象扩展

1、模板字符串

        let str = '这是模板字符串传值';
        let className = 'test';
        let html = `
                        
                        
                            

天气好

${str}
` ; console.log(html);

2、数组的扩展

        //Array.from 将伪数组,集合等转为数组
        let alllis = document.querySelectorAll('li');
        console.log(Array.isArray(alllis));//fasle
        Array.from(alllis);//转为数组
        
        //Array.of 将一些零散的东西转为数组
        console.log(Array.of(1,2,3,4));
        console.log(Array.of('张三','李四','王五'));

3、对象的扩展 在ES6中对象的key和value一样的时候只写一个就可以了

        let name = 'bob';
        let age = 12;
        let obj = {
            name,
            age
        };
        //Object.assign() 用于多个对象合并
        let obj1 = {name:'nnn'};
        let obj2 = {age:22};
        let obj3 = {sex:'男'};
        let obj = {};
        Object.assign(obj,obj1,obj2,obj3)

4、延展操作符

        let str1 = "我是个loser";
        let newArr = [...str1];
        console.log(newArr);//输出['我','是','个','l','o','s','e','r']

你可能感兴趣的:(vue常用的ES6语法--内置对象扩展)