首页 > 有人能说说 vue的store是什么鬼吗? 来个demo最好了

有人能说说 vue的store是什么鬼吗? 来个demo最好了

官网说的太简单了。

//store.js

export default {
    state : {
        count : 20
    },
    addsome (num) {
        this.state.count = this.state.count+Number(num)
    }
}

//component.js

<template>
    <div id="header">
        <button @click="add">点击</button>
        <p>还有{{initState2}}次机会</p>
    </div>
</template>
<script>
import store from '../../vuex/storeModule'
name : 'home',
    
    data () {
        return {
            initState: store.state.count
        }
    }
    methods : {
        add () {
            store.addsome(202)
        }
    }
</script>


这是我写的 为什么我点击button按钮 试图的数据变化不了呢  ??求大神答疑解难下

http://vuex.vuejs.org/zh-cn/intro.html
建议看看这个


addsome这个事件应该放进mutations里吧,之后actions再dispatch这个事件。
楼主文档再仔细看看。。
http://vuex.vuejs.org/zh-cn/mutations.html


vuex源码里一堆例子不会找来看?
https://github.com/vuejs/vuex/tree/master/examples


https://github.com/papersnake/newdenfaces-vue
不断更新中,等代码写完了再更新我的系列文章,不过我也是刚接触VUE+VUEX+VUE-ROUTER 所以用的不对的地方还请大家指点一下,


https://github.com/fegg/vue-vuex-router-demo

欢迎 star ……^_^


要了解vuex,先去看facebook的flux概念,然后看redux的概念。Vuex相当于是vue里面的redux


要的是 store模式的用法 都说 vuex干嘛


initState: store.state.count 这里改成 store.state,这个样子initState和store.state指向同一个对象,改变store.state的时候,initState才会跟着改变。initState: store.state.count这样子写其实就相当于:initState:20,和store对象没什么关系了。
个人感觉store模式类似于简化版的flux,而vuex类似于简化版的reduce。

【热门文章】
【热门文章】