首页 > 编程知识 正文

vue怎么用,vue常用的生命周期

时间:2023-05-06 04:26:01 阅读:11534 作者:2840

用Vue框架,熟悉它的生命周期可以让开发更好的进行。

首先先看看官网的图,详细的给出了vue的生命周期:

一共分为八个阶段。

beforeCreate (创建前)、

创建后,

beforeMount (加载前)、

加载后,

beforeUpdate (更新前)、

更新后,

beforeDestroy (销毁前)、

已销毁)

接下来,使用示例的demo展示一下具体的效果。

divid=' app ' { a }/divscriptvarmyvue=newvue (El : ' # app ',data: ) a: ) vue.js ), beforeCreate: function () { { { console.log ('创建前') console.log (this.a ) console.log (this.$ El ) }, created : function (({ { console.log ) '创建后) console.log (this.a ) console.log (this.$ El ) )、 before mount : function ((console.log (' mount之前) ) console.log (console.log ) this.log ($ El ) ), mounted : function ((console.log ) mount之后) ) console.log (this.a ) console.log (this.$ El ), before update : function ({ { console.log }“更新前”) console.log (this.a ) console.log (this.$ El ) )、 更新: function (({ { console.log )“更新完成”) console.log (this.a ) console.log (this.$ El ) )、 before destroy : function ({ { console.log ('销毁前') console.log (this.a ) console.log (this.$ El ) ) ) console e.log ) (“已销毁”) console.log ) this.a ) console.log(this.$El ) )/script

运行后,请检查控制台,

得到这个:

然后,将change方法添加到methods中。

divid=app { a } buttonv-on : click=' change ' change/button/div methods 3360 { change } { this.a=' change }

这就是vue的生命周期。 很简单吧。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。