http://jsrun.net/CcLKp/edit
## Vuex
Vuex是Vue.js 的狀態管理模式。
適用在大型單頁應用。
## 核心內容
* state 存放狀態數據
* mutations , 對state的成員操作
* getters 加工state成員給外界使用
* actions 異步操作
* modules 模塊化狀態管理
## Vuex VS. 簡單的store模式
```
var store = {
debug: true,
state: {
message: 'Hello!'
},
setMessageAction (newValue) {
if (this.debug) console.log('setMessageAction triggered with', newValue)
this.state.message = newValue
},
clearMessageAction () {
if (this.debug) console.log('clearMessageAction triggered')
this.state.message = ''
}
}
```
Store ,倉庫,基本就是一個容器, 包含著應用中大部分狀態(state)。
## Vuex VS. 單純的全局對象
1. Vuex 的狀態存儲是響應式的,Store變化,組件也自動變化
2. 不能直接改變Store中代替狀態
## Vuex 使用示例
```
<template>
<div>
<h2>Store Demo</h2>
<hr>
<h4> {{$store.state.myCount}}</h4>
<button @click="addMethod"> Add </button>
</div>
</template>
<script>
import store from '@/store'
export default {
name:'myCount',
store,
data(){
},
methods:{
addMethod(){
this.$store.commit('add');
}
}
}
</script>
<style scoped>
</style>
```
```
export default new Vuex.Store({
state: {
myCount:1
},
mutations: {
add(state){
state.myCount++;
},minus(state){
state.myCount--;
}
},
actions: {
},
modules: {
}
})
```
- 引入篇
- 基礎篇
- 快速入手
- 名詞解釋
- Vue語法
- Vue安裝
- Vue實例
- 模板語法
- 計算屬性和偵聽器
- Class與Style綁定
- 條件渲染
- 列表渲染
- 事件處理
- 表單輸入綁定
- 組件基礎
- 進階篇
- 常用模塊
- 單文件組件
- 快速學會Vue Router路由
- Vue Route 進階使用
- Vuex 與狀態管理
- Axios
- Mock.js
- data數據顯示在頁面
- Vue生命周期
- Vue按需加載組件
- 國際化
- 頁面加載進度條 -NProgress
- 自定義主題顏色
- 開發篇
- Vue入門——創建并運行一個Vue項目
- Vue + Element UI 項目創建
- 使用Vue ui項目創建工具在網頁中創建Vue項目
- Vue項目創建入門實例
- Vue CLI
- 創建項目
- 使用Visual Studio Code 開發Vue項目
- 高級篇
- 組件深入
- Vue+Element
- Vue + ElementUI 主題顏色切換
- 工具篇
- 在線代碼編輯器
- 開發工具(IDE,集成開發環境)
- npm(JavaScript包管理工具)介紹
- Node.js(npm)在Windows下安裝
- webpack介紹
- webpack快速實例
- webpack
- 快速入門實例
- 安裝
- 概念
- Nodejs
- 基礎
- npm
- 命令參考
- 命令
- 模塊安裝
- Babel
- 問題解決篇
- ERROR Failed to get response from https://registry.yarnpkg.com/vue-cli-version -marker
- Vue常見問題
- You are using the runtime-only build of Vue where the template compiler is not
- yarn 報unable to get local issuer certificate
- yarn There appears to be trouble with your network connection. Retrying
- Expected Boolean, got String with value "true".
- 項目篇
- 項目創建
- 項目設計
- 頁面
- 開發問題
- 后端
- Spring Boot + Activiti 工作流框架搭建之一
- Spring Boot + Activiti 工作流框架搭建之二
- 工作流
- Java流程框架
- Activiti
- 頁面風格
- green
- blue
- orange
- 參考篇
- 好的Git項目
- Vue的在線js
- 指令
- 開發說明
- JavaScript 高級
- export和import
- JS模塊化規范對比以及在Node.js的實現
- Storage
- ES2015
- scss
- CSS、Sass、SCSS