vue生命周期

Vue.use(Vuex)
	const store=new Vuex.Store({
		state:{
			count:10
		},
		getters:{

		},
		mutations:{
			INCRENENT(state){
				state.count++
			}
		},
		actions:{
			inputevent({commit}){
				commit('INCRENENT')
			}
		}
	})
	var vm=new Vue({
		el:"#app",
		data:{
			title:"2123456"
		},
		beforeCreate(){
			console.log("我是第一")
		},
		created(){
			console.log("我是第二")
		},
		beforeMount(){
			console.log("我是第三")
		},
		mounted(){
			console.log("我是第四")
		},
		beforeUpdate(){
			console.log("我是第五")
		},
		updated(){
			console.log("我是第六")
		},
		activated(){
			console.log("组件被激活时调用")
		},
		deactivated(){
			console.log("组件被移除时调用")
		},
		beforeDestory(){
			console.log("组件销毁前调用")
		},
		destoryed(){
			console.log("组件销毁后调用")
		},
		methods:{
			click(){
				console.log('我是方法')
				this.$store.dispatch('inputevent')
			}
		},
		store
	})

  

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

  

posted @ 2017-09-26 17:08  fm060  阅读(148)  评论(0)    收藏  举报