zoukankan      html  css  js  c++  java
  • 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       组件销毁后
  • 相关阅读:
    Nacos配置管理-什么是配置中心
    MYSQL count
    贷款
    短视频推荐图书
    前端
    err
    err
    Mysql8安装教程
    err
    err
  • 原文地址:https://www.cnblogs.com/zhizu/p/6867371.html
Copyright © 2011-2022 走看看