鍍金池/ 問(wèn)答/HTML/ 有人能說(shuō)說(shuō) vue的store是什么鬼嗎? 來(lái)個(gè)demo最好了

有人能說(shuō)說(shuō) vue的store是什么鬼嗎? 來(lái)個(gè)demo最好了

官網(wǎng)說(shuō)的太簡(jiǎn)單了。

//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">點(diǎn)擊</button>
        <p>還有{{initState2}}次機(jī)會(huì)</p>
    </div>
</template>
<script>
import store from '../../vuex/storeModule'
name : 'home',
    
    data () {
        return {
            initState: store.state.count
        }
    }
    methods : {
        add () {
            store.addsome(202)
        }
    }
</script>


這是我寫(xiě)的 為什么我點(diǎn)擊button按鈕 試圖的數(shù)據(jù)變化不了呢  ??求大神答疑解難下
回答
編輯回答
吢涼
2017年5月7日 13:58
編輯回答
晚風(fēng)眠
2018年5月12日 13:18
編輯回答
墨染殤

https://github.com/papersnake/newdenfaces-vue
不斷更新中,等代碼寫(xiě)完了再更新我的系列文章,不過(guò)我也是剛接觸VUE+VUEX+VUE-ROUTER 所以用的不對(duì)的地方還請(qǐng)大家指點(diǎn)一下,

2017年12月14日 02:21
編輯回答
歆久

addsome這個(gè)事件應(yīng)該放進(jìn)mutations里吧,之后actions再dispatch這個(gè)事件。
樓主文檔再仔細(xì)看看。。
http://vuex.vuejs.org/zh-cn/mutations.html

2018年5月16日 17:30
編輯回答
她愚我

initState: store.state.count 這里改成 store.state,這個(gè)樣子initState和store.state指向同一個(gè)對(duì)象,改變store.state的時(shí)候,initState才會(huì)跟著改變。initState: store.state.count這樣子寫(xiě)其實(shí)就相當(dāng)于:initState:20,和store對(duì)象沒(méi)什么關(guān)系了。
個(gè)人感覺(jué)store模式類似于簡(jiǎn)化版的flux,而vuex類似于簡(jiǎn)化版的reduce。

2017年12月27日 05:17
編輯回答
柒喵

要了解vuex,先去看facebook的flux概念,然后看redux的概念。Vuex相當(dāng)于是vue里面的redux

2017年12月15日 15:48
編輯回答
別逞強(qiáng)

要的是 store模式的用法 都說(shuō) vuex干嘛

2017年1月21日 23:08