vuex 跟 vue属性

 

import Vue from 'vue'

import Vuex,{store} from 'vuex'

Vue.use(Vuex)

const store = new store({

state:{}

getters:{}过滤改变state

mutations:{ 改变state,处理同步请求

changName(state,actions){

  state.name = actions.name 

}

}

<-- 在组件里面 this.$store.commit('changName',{name:"张三'})-->

actions:{  改变mutations 处理异步请求

  getlist(context){

  context.commit('initlist',{list:res.data})

  <-- 在组件生命周期或事件中

  this.$store.dispatch('getlist')  去触发这个方法

  -->

}

}

})

 

 

--------------------------

computed:{ 计算属性

  getlist(){

return Math.floor(Math.random()*this.username)

}

} 仅仅在内部依赖的data中数据发生变化时才执行

watch:{监听属性

getlist(newval,oldval){}

基于计算属性来监听新的值跟旧的值

}

posted @ 2020-12-18 16:49  人心不古  阅读(59)  评论(0编辑  收藏  举报