美文网首页
vue生命周期

vue生命周期

作者: 黄鹤你不是人 | 来源:发表于2017-10-27 15:28 被阅读0次

    vue的生命周期如图所示:

    vue生命周期图例

    它可以总共分为8个阶段:
    beforeCreate(创建前),
    created(创建后),
    beforeMount(载入前),
    mounted(载入后),
    beforeUpdate(更新前),
    updated(更新后),
    beforeDestroy(销毁前),
    destroyed(销毁后)

    create 和 mounted 相关

    beforecreated:el 和 data 并未初始化
    created:完成了 data 数据的初始化,el没有
    beforeMount:完成了 el 和 data 初始化
    mounted :完成挂载

    应用场景

    beforecreate : 举个栗子:可以在这加个loading事件
    created :在这结束loading,还做一些初始化,实现函数自执行
    mounted : 在这发起后端请求,拿回数据,配合路由钩子做一些事情
    beforeDestory: 你确认删除XX吗?
    destoryed :当前组件已被删除,清空相关内容

    相关文章

      网友评论

          本文标题:vue生命周期

          本文链接:https://www.haomeiwen.com/subject/fawhpxtx.html