Vue生命周期

Posted cuter、

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Vue生命周期相关的知识,希望对你有一定的参考价值。

/*
常用的生命周期钩子:
		1.mounted: 发送ajax请求、启动定时器、绑定自定义事件、订阅消息等【初始化操作】。
		2.beforeDestroy: 清除定时器、解绑自定义事件、取消订阅消息等【收尾工作】。
关于销毁Vue实例
		1.销毁后借助Vue开发者工具看不到任何信息。
		2.销毁后自定义事件会失效,但原生DOM事件依然有效。
		3.一般不会在beforeDestroy操作数据,因为即便操作数据,也不会再触发更新流程了。

*/
            beforeCreate() {
			console.log('beforeCreate')
			},
			created() {
				console.log('created')
			},
			beforeMount() {
				console.log('beforeMount')
			},
			mounted() {
			//常用
				console.log('mounted')
			},
			beforeUpdate() {
				console.log('beforeUpdate')
			},
			updated() {
				console.log('updated')
			},
			beforeDestroy() {
			//常用
				console.log('beforeDestroy')
			},
			destroyed() {
			//一般不会在这里操作数据
				console.log('destroyed')
			},

以上是关于Vue生命周期的主要内容,如果未能解决你的问题,请参考以下文章