vue1.0和vue2.0的区别(一)

今天我们来说一说vue1.0和vue2.0的主要变化有哪些

一.在每个组件模板,不在支持片段代码

VUE1.0是: 

<template>
    <h3>我是组件</h3><strong>我是加粗标签</strong>
</template>

VUE2.0:必须有根元素,包裹住所有的代码

<template id="aaa">
    <div>
        <h3>我是组件</h3>
            <strong>我是加粗标签</strong>
     </div>
</template>

二.关于组件定义

VUE1.0定义组件的方式有:

Vue.extend            这种方式,在2.0里面有,但是有一些改动

Vue.component(组件名称,{    在2.0继续能用
    data(){}
    methods:{}
    template:
});

VUE2.0定义组件的方式则更为简单

var Home={
        template:''        ->   相当于Vue.extend()
};

三.生命周期的变化

vue1.0的生命周期为

init                     ->初始化
created                  ->创建
beforeCompile            ->编译之前
compiled                 ->编译完成
ready        √           -> mounted
beforeDestroy            ->销毁之前
destroyed                ->已经销毁

vue2.0的生命周期为(标*的为经常用的)

beforeCreate    组件实例刚刚被创建,属性都没有
created         实例已经创建完成,属性已经绑定
beforeMount     模板编译之前
mounted         模板编译之后,代替之前ready  *
beforeUpdate    组件更新之前
updated         组件更新完毕    *
beforeDestroy   组件销毁前
destroyed       组件销毁后

 

posted @ 2017-05-17 14:24  自足  阅读(920)  评论(0编辑  收藏  举报