vueJS2.0

常量和变量

  • let 来声明变量

  • const来声明常量,常量一旦声明无法改变

  • 字符串的拼接

let name = "xmg";
    let age = 10;
    let  res = `我叫${name}--年龄${age}`;
    alert(res);

    let list = ['1','2','3'];
    let list2 = ['4','5','6'];
    //...数组的名称  展开数组
    let resList = [...list,...list2];

    /*对象赋值*/
    let obj = {name:'123',age:0,address:'123'};
    let obj1 = {name:'xmg',age:12}
    let obj2 = {name:'gxq',age:10,address:'address'};
    /*合并对象 如果有相同的key,后面的对象会给前面的对象,给覆盖掉。*/
    Object.assign(obj,obj2);

    console.log(obj);

    let obj3  = {
        name() {
            alert('name');
        }
    }
    obj3.name();

箭头函数

  • 箭头函数就是对匿名函数的简写
var fnres = function () {

     }

 var fn = ()=>{
     alert('show');
     }
     fn();

let fn2 = function (args) {
        alert(args);
    }
    fn2(10)

//拥有一个参数可以用以下方式简写
let fn2 = args => {
        alert(args);
    }
    fn2(10);

 this.$http.get('/someUrl').then( response=> {

    }, response => {
        // error callback
    });

元组

  function test() {

        return ['10','20'];
    }


    let [a,b] = test();
    console.log(a,b);


    /*结构对象*/
    function breakfast() {
        return {dessert:'bra1',drink:'bra2',fruits:'bra3'}
    }
    /*把对象当中的属性赋值给结构*/
    let {dessert:dessert,drink:drink,fruits:fruits} = breakfast();
    console.log(dessert,drink,fruits);


    class baby{

        constructor(weight,sex){  //构造方法:在创建实例时,会自动调用该方法 初始化方法
            this.weight  = weight;
            this.sex = sex;
            this.age = 1;
        }

        show(){
            alert(this.weight+this.sex+this.age);
        }

        get xmg(){ /*get方法什么时候调用:*/
            return this.age;
        }

        set xmg(val){
            alert(val);
        }


        static say(){ /*静态方法:不需要创建对象,直接使用类名调用的方法 叫静态方法*/
            alert("hello world");
        }

    }

/*   var per = new baby('8','男');
    per.show();*/

    var per2 = new baby('5','女');
    //alert(per2.xmg);//会自动调用该属性的get方法。
    per2.xmg = 10;
    /*baby.say();*/

路由的区别

    // 1. 定义(路由)组件。
    const home = { template: '
home
' } const music = { template: '
music
' } const singer = { template: '
singer
' } // 2.定义路由 const routes = [ { path: '/home', component: home , children:[{ path: '/login', component: music }] }, { path: '/music', component: music }, { path: '/singer', component: singer }, { path: '/', redirect: '/home' } ]; /*3. 创建 router 实例,然后传 `routes` 配置*/ const router = new VueRouter({ routes // (缩写)相当于 routes: routes }) const app = new Vue({ router }).$mount('#app')

你可能感兴趣的:(vueJS2.0)