var vm = new Vue({ el:'#app', beforeCreate:function(){ console.log('before create') } })
var vm = new Vue({ el:'#app', beforeCreate:function(){ console.log('before create') }, created:function(){ console.log('created') } })
可以看到beforeCreate执行之后,created也被自动的执行了,继续看这张图
var vm = new Vue({ el:'#app', template:'<h1>hello</h1>', beforeCreate:function(){ console.log('before create') }, created:function(){ console.log('created') }, beforeMount:function(){ console.log('before mount') } })
<div id='app'> hello world </div> <script> var vm = new Vue({ el:'#app', template:'<h1>hello</h1>', beforeCreate:function(){ console.log('before create') }, created:function(){ console.log('created') }, beforeMount:function(){ console.log(this.$el); console.log('before mount') }, mounted:function(){ console.log(this.$el); console.log('mounted') } }) </script>
var vm = new Vue({ el:'#app', template:'<h1>hello</h1>', beforeCreate:function(){ console.log('before create') }, created:function(){ console.log('created') }, beforeMount:function(){ console.log(this.$el); console.log('before mount') }, mounted:function(){ console.log(this.$el); console.log('mounted') }, beforeDestroy:function(){ console.log('beforeDestroy') }, destroyed:function(){ console.log('destroyed') } })
var vm = new Vue({ el:'#app', template:'<h1>hello</h1>', beforeCreate:function(){ console.log('before create') }, created:function(){ console.log('created') }, beforeMount:function(){ console.log(this.$el); console.log('before mount') }, mounted:function(){ console.log(this.$el); console.log('mounted') }, beforeDestroy:function(){ console.log('beforeDestroy') }, destroyed:function(){ console.log('destroyed') }, beforeUpdate:function(){ console.log('before updated') }, updated:function(){ console.log('updated') } })