# 狀態管理vuex
# Vuex基本概念
Vuex 是一個專為 Vue.js 應用程序開發的狀態管理插件。它采用集中式存儲管理應用的所有組件的狀態,并支持通過命名空間組織和管理狀態樹。一般狀態要配合存儲實現持久化。
每一個 Vuex 應用的核心就是 store(倉庫)。store包含應用中大部分的狀態 (state)。Vuex 和單純的全局對象有以下兩點不同:
1. Vuex 的狀態存儲是響應式的。當 Vue 組件從 store 中讀取狀態的時候,若 store 中的狀態發生變化,那么相應的組件也會相應地得到高效更新。
2. store 中的狀態是只讀的,改變 store 中的狀態的唯一途徑就是顯式地提交修改器mutation。
uni-app中集成了Vuex,整個應用只允許定義一個store,uni-app建議使用注入的方式使用vuex,然后我們需要做的是定義store的邏輯,然后在main.js文件中引用這個store就可以了。一個標準的store的定義如下,包含狀態(state)、修改器(mutations)、動作(actions)和讀取器(getters)四個部分。
如果一個項目比較復雜,可以通過模塊來進行管理。
```
import Vue from 'vue'
import Vuex from 'vuex'
import createLogger from 'vuex/dist/logger'
Vue.use(Vuex)
const debug = true;
Vue.use(Vuex)
export default new Vuex.Store({
modules: {
},
state,
actions,
getters,
mutations,
strict: debug, //設置運行模式
plugin: debug ? [createLogger()] : [] //調試模式加入日志插件
})
```
詳細官方文檔可以參考:[https://vuex.vuejs.org/zh/
](https://vuex.vuejs.org/zh/)
完整的定義可能還包含日志輸出
# 簡單的計數器
首先看下最簡單的版本,這個store只包含一個狀態count,由于Vuex只能通過mutuations修改狀態,因此定義increament和decrement兩個修改器改變count的值。
## store的定義
在單獨的文件中定義store,然后在main.js中導入定義好的store。
store/index.js
```
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
count:0
},
mutations: {
increment(state) {
state.count++
},
decrement(state) {
state.count--
}
}
})
export default store
```
將定義的store文件通過import語句導入
```
import store from './store'
```
上述語句實際是導入默認的文件index.js
```
import store from './store/index'
```
然后修改Vue的原型prototype,使得store全局可用
```
Vue.prototype.$store = store
```
最后生成Vue的實例的時候將定義的store傳給構造函數
```
const app = new Vue({
store,
...App
})
```
完整的main.js文件:
```
import Vue from 'vue'
import App from './App'
import store from './store/index.js'
Vue.config.productionTip = false
Vue.prototype.$store = store
App.mpType = 'app'
const app = new Vue({
store,
...App
})
app.$mount()
```
由于store掛在app實例的原型上,因此全局可用。在頁面文件中可以通過this.$store訪問store。例如訪問state中的count狀態變量
```
this.$store.state.count
```
## 頁面中使用store
下面看看頁面文件如何使用vuex。在頁面文件中為方便訪問,通過計算屬性簡單的封裝狀態變量的訪問(后面會介紹通過mapState簡單的實現映射)。
現在,你可以通過 this.$store.state 來獲取狀態對象,
```
computed: {
counter() {
return this.$store.state.count;
}
},
```
通過 this.$store.commit 方法觸發狀態變更:
```
methods: {
increment(){
this.$store.commit('increment')
},
decrement(){
this.$store.commit('decrement')
}
}
```
完整的示例代碼:
pages/index/about.vue
```
<template>
<view class="content">
<text class="title">{{ counter }}</text>
<view class="">
<button @tap="doIncrement">+</button>
<button @tap="doDecrement">-</button>
</view>
</view>
</template>
<script>
export default {
computed: {
counter () {
return this.$store.state.count;
}
},
methods: {
doIncrement() {
this.$store.commit('increment');
},
doDecrement() {
this.$store.commit('decrement');
}
},
}
</script>
<style>
.content {
flex: 1;
justify-content: center;
align-items: center;
}
.title {
font-size: 36upx;
color: #8f8f94;
}
</style>
```
運行效果:

> 再次強調,我們通過提交 mutation 的方式,而非直接改變 store.state.count,是因為我們想要更明確地追蹤到狀態的變化。這個簡單的約定能夠讓你的意圖更加明顯,這樣你在閱讀代碼的時候能更容易地解讀應用內部的狀態改變。
由于 store 中的狀態是響應式的,在組件中調用 store 中的狀態簡單到僅需要在計算屬性中返回即可。觸發變化也僅僅是在組件的 methods 中提交 mutation。
# State
Vuex 使用單一狀態樹,用一個對象就包含了全部的應用層級狀態,作為一個“唯一數據源”而存在。這也意味著,每個應用將僅僅包含一個 store 實例。單一狀態樹讓我們能夠直接地定位任一特定的狀態片段,在調試的過程中也能輕易地取得整個當前應用狀態的快照。
那么我們如何在 Vue 組件中展示狀態呢?由于 Vuex 的狀態存儲是響應式的,從 store 實例中讀取狀態最簡單的方法就是在計算屬性中返回某個狀態:
```
<script>
export default {
computed: {
counter {
return this.$store.state.count;
}
},
methods: {
increment(){
return this.$store.commit('increment')
},
decrement(){
return this.$store.commit('decrement')
}
}
}
</script>
```
每當 store.state.count 變化的時候, 都會重新求取計算屬性,并且觸發更新相關聯的文檔對象模型 (Document Object Model : DOM)。然而,這種模式導致組件依賴全局狀態單例。uni-app將狀態從根組件“注入”到每一個子組件中(需調用 `Vue.use(Vuex)`),通過在根實例中注冊 store 選項,該 store 實例會注入到根組件下的所有子組件中,且子組件能通過`this.$store` 訪問到。
當一個組件需要獲取多個狀態時候,將這些狀態都聲明為計算屬性會有些重復和冗余。為了解決這個問題,我們可以使用 mapState 輔助函數幫助我們生成計算屬性,mapState 函數返回的是一個對象。使用對象展開運算符`…`,我們可以極大地簡化寫法:
```
<script>
import {
mapState,
mapMutations,
mapActions
} from 'vuex'
export default {
computed: {
...mapState(['count']),
},
}
</script>
```
如果你不想使用store中定義的名字,或者說命名有沖突,可以取個別名:
```
computed: {
// ...mapState(['count']),
...mapState({
counter: state => state.count,
}),
},
```
使用 Vuex 并不意味著你需要將所有的狀態放入 Vuex。雖然將所有的狀態放到 Vuex 會使狀態變化更顯式和易調試,但也會使代碼變得冗長和不直觀。如果有些狀態嚴格屬于單個組件,最好還是作為組件的局部狀態。你應該根據你的應用開發需要進行權衡和確定。
# Getter
有時候我們需要從 store 中的 state 中派生出一些狀態,例如對列表進行過濾并計數:
```
computed: {
doneTodosCount () {
return this.$store.state.todos.filter(todo => todo.done).length
}
}
```
如果有多個組件需要用到此屬性,我們要么復制這個函數,或者抽取到一個共享函數然后在多處導入它——無論哪種方式都不是很理想。
Vuex 允許我們在 store 中定義“getter”(可以認為是 store 的計算屬性)。就像計算屬性一樣,getter 的返回值會根據它的依賴被緩存起來,且只有當它的依賴值發生了改變才會被重新計算。
Getter 接受 state 作為其第一個參數:
```
const store = new Vuex.Store({
state: {
todos: [
{ id: 1, text: '...', done: true },
{ id: 2, text: '...', done: false }
]
},
getters: {
doneTodos: state => {
return state.todos.filter(todo => todo.done)
}
}
})
```
Getter 會暴露為 store.getters 對象,你可以以屬性的形式訪問這些值:
```
store.getters.doneTodos // -> [{ id: 1, text: '...', done: true }]
this.$store.getters.doneTodos;
```
Getter 也可以接受其他 getter 作為第二個參數,通過這種機制可以訪問其他的Getter:
```
getters: {
// ...
doneTodosCount: (state, getters) => {
return getters.doneTodos.length
}
}
```
我們可以很容易地在任何組件中使用它:
```
computed: {
doneTodosCount () {
return this.$store.getters.doneTodosCount
}
}
```
注意,getter 在通過屬性訪問時是作為 Vue 的響應式系統的一部分緩存其中的。
你也可以通過讓 getter 返回一個函數,來實現給 getter 傳參。在你對 store 里的數組進行查詢時非常有用。
```
getters: {
// ...
getTodoById: (state) => (id) => {
return state.todos.find(todo => todo.id === id)
}
}
```
用法:
```
store.getters.getTodoById(2) // -> { id: 2, text: '...', done: false }
```
注意,getter 在通過方法訪問時,每次都會去進行調用,而不會緩存結果。
mapGetters 輔助函數僅僅是將 store 中的 getter 映射到局部計算屬性:
```
import { mapGetters } from 'vuex'
export default {
// ...
computed: {
// 使用對象展開運算符將 getter 混入 computed 對象中
...mapGetters([
'doneTodosCount',
'anotherGetter',
// ...
])
}
}
```
如果你想將一個 getter 屬性另取一個名字,使用對象形式:
```
mapGetters({
// 把 `this.doneCount` 映射為 `this.$store.getters.doneTodosCount`
doneCount: 'doneTodosCount'
})
```
# Mutation
更改 Vuex 的 store 中的狀態的唯一方法是提交 mutation。Vuex 中的 mutation 非常類似于事件:每個 mutation 都有一個字符串的事件類型 (type) 和 一個 回調函數 (handler)。這個回調函數就是我們實際進行狀態更改的地方,并且它會接受 state 作為第一個參數:
```
const store = new Vuex.Store({
state: {
count: 1
},
mutations: {
increment (state) {
// 變更狀態
state.count++
}
}
})
```
你不能直接調用一個 mutation handler。這個選項更像是事件注冊:“當觸發一個類型為 increment 的 mutation 時,調用此函數。”要喚醒一個 mutation handler,你需要以相應的 type 調用 store.commit 方法:
store.commit('increment')
```
提交載荷(Payload)
```
你可以向 store.commit 傳入額外的參數,即 mutation 的 載荷(payload):
```
mutations: {
increment (state, n=1) {
state.count += n
}
}
store.commit('increment', 10)
```
在大多數情況下,載荷應該是一個對象,這樣可以包含多個字段并且記錄的 mutation 會更易讀:
```
mutations: {
increment (state, payload) {
state.count += payload.amount
}
}
```
如果你要傳遞多個參數,必須得把這些參數封裝為一個對象的形式傳遞。
```
store.commit('increment', {
amount: 10
})
```
## 對象風格的提交方式
提交 mutation 的另一種方式是直接使用包含 type 屬性的對象:
```
store.commit({
type: 'increment',
amount: 10
})
```
當使用對象風格的提交方式,整個對象都作為載荷傳給 mutation 函數,因此 handler 保持不變:
```
mutations: {
increment (state, payload) {
state.count += payload.amount
}
}
```
## Mutation 需遵守 Vue 的響應規則
既然 Vuex 的 store 中的狀態是響應式的,那么當我們變更狀態時,監視狀態的 Vue 組件也會自動更新。這也意味著 Vuex 中的 mutation 也需要與使用 Vue 一樣遵守一些注意事項:
1. 提前在你的 store 中初始化所有所需屬性。
2. 當需要在對象上添加新屬性時,你應該使用 Vue.set(obj, 'newProp', 123), 或者以新對象替換老對象。例如,利用對象展開運算符我們可以這樣寫:
```
state.obj = { ...state.obj, newProp: 123 }
```
## Mutation 必須是同步函數
一條重要的原則就是要記住 mutation 必須是同步函數。為什么?請參考下面的例子:
```
mutations: {
someMutation (state) {
api.callAsyncMethod(() => {
state.count++
})
}
}
```
現在想象,我們正在 debug 一個 app 并且觀察 devtool 中的 mutation 日志。每一條 mutation 被記錄,devtools 都需要捕捉到前一狀態和后一狀態的快照。然而,在上面的例子中 mutation 中的異步函數中的回調讓這不可能完成:因為當 mutation 觸發的時候,回調函數還沒有被調用,devtools 不知道什么時候回調函數實際上被調用——實質上任何在回調函數中進行的狀態的改變都是不可追蹤的。
## 在組件中提交 Mutation
你可以在組件中使用`this.$store.commit('xxx')` 提交 mutation,或者使用 mapMutations 輔助函數將組件中的 methods 映射為 store.commit 調用(需要在根節點注入 store)。
```
import {
mapMutations
} from 'vuex'
export default {
// ...
methods: {
...mapMutations([
// 將this.increment()映射為 `this.$store.commit('increment')
'increment',
// 將this.incrementBy(amount)映射為this.$store.commit('incrementBy', amount)
'incrementBy'
]),
...mapMutations({
// 將this.add()映射為 this.$store.commit('increment')
add: 'increment'
})
}
}
```
# Action
Action 類似于 Mutation,不同在于:
1. Action 提交的是 Mutation,而不是直接變更狀態。
2. Action 可以包含任意異步操作。
讓我們來注冊一個簡單的 action:
```
const store = new Vuex.Store({
state: {
count: 0
},
mutations: {
increment (state) {
state.count++
}
},
actions: {
increment (context) {
context.commit('increment')
}
}
})
```
Action 函數接受一個與 store 實例具有相同方法和屬性的 context 對象,因此你可以調用 context.commit 提交一個 mutation,或者通過 context.state 和 context.getters 來獲取 state 和 getters。
實踐中,我們會經常用到 ES2015 的 參數解構 來簡化代碼(特別是我們需要調用 commit 很多次的時候):
```
actions: {
increment ({ commit }) {
commit('increment')
}
}
```
`{commit}`意思是從context中提取commit對象方法。
## 分發 Action
Action 通過 store.dispatch 方法觸發:
```
store.dispatch('increment')
```
乍一眼看上去感覺多此一舉,我們直接分發 mutation 豈不更方便?實際上并非如此,還記得 mutation 必須同步執行這個限制么?Action 就不受約束!我們可以在 action 內部執行異步操作:
```
actions: {
incrementAsync ({ commit }) {
setTimeout(() => {
commit('increment')
}, 1000)
}
}
```
Actions 支持同樣的載荷方式和對象方式進行分發:
```
// 以載荷形式分發
store.dispatch('incrementAsync', {
amount: 10
})
```
或者以對象的形式分發
```
// 以對象形式分發
store.dispatch({
type: 'incrementAsync',
amount: 10
})
```
## 在組件中分發 Action
你在組件中使用`this.$store.dispatch('xxx')`分發 action,或者使用 mapActions 輔助函數將組件的 methods 映射為 store.dispatch 調用:
```
import {
mapActions
} from 'vuex'
export default {
// ...
methods: {
...mapActions([
// 將this.increment()映射為this.$store.dispatch('increment')
'increment',
// 將`this.incrementBy(amount) 映射為`this.$store.dispatch('incrementBy', amount)
'incrementBy'
]),
...mapActions({
// 將this.add()映射為this.$store.dispatch('increment')
add: 'increment'
})
}
}
```
> 使用mapActions, mapMutations要注意不能有重名的方法,否則需要在使用mapActions, mapMutations時候重命名映射方法名稱,例如
```
methods:{
increment() {
},
...mapActions({
// 將this.add()映射為this.$store.dispatch('increment')
add: 'increment'
})
}
```
## 組合 Action
Action 通常是異步的,那么如何知道 action 什么時候結束呢?更重要的是,我們如何才能組合多個 action,以處理更加復雜的異步流程?
首先,你需要明白 store.dispatch 可以處理被觸發的 action 的處理函數返回的 Promise,并且 store.dispatch 仍舊返回 Promise:
```
actions: {
actionA ({ commit }) {
return new Promise((resolve, reject) => {
setTimeout(() => {
commit('someMutation')
resolve()
}, 1000)
})
}
}
```
現在你可以:
```
store.dispatch('actionA').then(() => {
// ...
})
```
在另外一個 action 中也可以:
```
actions: {
// ...
actionB ({ dispatch, commit }) {
return dispatch('actionA').then(() => {
commit('someOtherMutation')
})
}
}
```
最后,如果我們利用 async / await,我們可以如下組合 action:
```
// 假設 getData() 和 getOtherData() 返回的是 Promise
actions: {
async actionA ({ commit }) {
commit('gotData', await getData())
},
async actionB ({ dispatch, commit }) {
await dispatch('actionA') // 等待 actionA 完成
commit('gotOtherData', await getOtherData())
}
}
```
一個 store.dispatch 在不同模塊中可以觸發多個 action 函數。在這種情況下,只有當所有觸發函數完成后,返回的 Promise 才會執行。
完整的代碼清單
store/index.js
```
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
count: 0
},
mutations: {
increment(state, n = 1) {
state.count += n;
},
decrement(state, n = 1) {
state.count -= n;
}
},
actions: {
incrementIfOdd(context) {
if ((context.state.count + 1) % 2 === 0) {
context.commit('increment')
}
},
incrementAsync(context) {
// console.log(context);
setTimeout(() => {
context.commit('increment')
}, 1000)
}
},
getters: {
total(state) {
return state.count;
}
}
})
export default store
pages/index/index.vue
<template>
<view>
<view>Clicked: {{ count }} times use state</view>
<view>Clicked: {{ total }} times use getter</view>
<button @click="increment()">+</button>
<button @click="decrement()">-</button>
<button @click="incrementIfOdd()">Increment if odd</button>
<button @click="incrementAsync()">Increment async</button>
</view>
</template>
<script>
import {
mapState,
mapMutations,
mapActions
} from 'vuex'
export default {
computed: {
// ...mapState(['count']),
...mapState({
count: state => state.count,
}),
total() {
return this.$store.getters.total;
}
},
methods: {
// ...mapMutations(['increment', 'decrement']),
...mapMutations({
increment: 'increment',
decrement: 'decrement'
}),
// ...mapActions(['incrementIfOdd', 'incrementAsync'])
...mapActions({
incrementIfOdd: 'incrementIfOdd',
incrementAsync: 'incrementAsync'
})
}
}
</script>
```
# Module與子狀態
由于使用單一狀態樹,應用的所有狀態會集中到一個比較大的對象。當應用變得非常復雜時,store 對象就有可能變得相當臃腫。
為了解決以上問題,Vuex 允許我們將 store 分割成模塊(module)。每個模塊擁有自己的 state、mutations、actions、getters,并通過namespaced屬性支持命名空間訪問相應的對象:
```
const moduleA = {
namespaced: true,
state: { ... },
mutations: { ... },
actions: { ... },
getters: { ... }
}
const moduleB = {
namespaced: true,
state: { ... },
mutations: { ... },
actions: { ... }
}
const store = new Vuex.Store({
modules: {
a: moduleA,
b: moduleB
}
})
store.state.a // -> moduleA 的狀態
store.state.b // -> moduleB 的狀態
```
## 模塊的局部狀態
對于模塊內部的 mutation 和 getter,接收的第一個參數是模塊的局部狀態對象。
```
const moduleA = {
namespaced: true,
state: { count: 0 },
mutations: {
increment (state) {
// 這里的 `state` 對象是模塊的局部狀態
state.count++
}
},
getters: {
doubleCount (state) {
return state.count * 2
}
}
}
```
同樣,對于模塊內部的 action,局部狀態通過 context.state 暴露出來,根節點狀態則為 context.rootState:
```
const moduleA = {
// ...
actions: {
incrementIfOddOnRootSum ({ state, commit, rootState }) {
if ((state.count + rootState.count) % 2 === 1) {
commit('increment')
}
}
}
}
```
對于模塊內部的 getter,根節點狀態會作為第三個參數暴露出來:
```
const moduleA = {
// ...
getters: {
sumWithRootCount (state, getters, rootState) {
return state.count + rootState.count
}
}
}
```
命名空間
默認情況下,模塊內部的 action、mutation 和 getter 是注冊在全局命名空間的——這樣使得多個模塊能夠對同一 mutation 或 action 作出響應。
如果希望你的模塊具有更高的封裝度和復用性,你可以通過添加 namespaced: true 的方式使其成為帶命名空間的模塊。當模塊被注冊后,它的所有 getter、action 及 mutation 都會自動根據模塊注冊的路徑調整命名。例如:
```
const store = new Vuex.Store({
modules: {
account: {
namespaced: true,
// 模塊內容(module assets)
state: { ... }, // 模塊內的狀態已經是嵌套的了,使用 `namespaced` 屬性不會對其產生影響
getters: {
isAdmin () { ... } // -> getters['account/isAdmin']
},
actions: {
login () { ... } // -> dispatch('account/login')
},
mutations: {
login () { ... } // -> commit('account/login')
},
// 嵌套模塊
modules: {
// 繼承父模塊的命名空間
myPage: {
state: { ... },
getters: {
profile () { ... } // -> getters['account/profile']
}
},
// 進一步嵌套命名空間
posts: {
namespaced: true,
state: { ... },
getters: {
popular () { ... } // -> getters['account/posts/popular']
}
}
}
}
}
})
```
啟用了命名空間的 getter 和 action 會收到局部化的 getter,dispatch 和 commit。換言之,你在使用模塊內容(module assets)時不需要在同一模塊內額外添加空間名前綴。更改 namespaced 屬性后不需要修改模塊內的代碼。
在帶命名空間的模塊內訪問全局內容(Global Assets)
如果你希望使用全局 state 和 getter,rootState 和 rootGetter 會作為第三和第四參數傳入 getter,也會通過 context 對象的屬性傳入 action。
若需要在全局命名空間內分發 action 或提交 mutation,將`{ root: true }` 作為第三參數傳給 dispatch 或 commit 即可。
```
modules: {
foo: {
namespaced: true,
getters: {
// 在這個模塊的 getter 中,`getters` 被局部化了
// 你可以使用 getter 的第四個參數來調用 `rootGetters`
someGetter (state, getters, rootState, rootGetters) {
getters.someOtherGetter // -> 'foo/someOtherGetter'
rootGetters.someOtherGetter // -> 'someOtherGetter'
},
someOtherGetter: state => { ... }
},
actions: {
// 在這個模塊中, dispatch 和 commit 也被局部化了
// 他們可以接受 `root` 屬性以訪問根 dispatch 或 commit
someAction ({ dispatch, commit, getters, rootGetters }) {
getters.someGetter // -> 'foo/someGetter'
rootGetters.someGetter // -> 'someGetter'
dispatch('someOtherAction') // -> 'foo/someOtherAction'
dispatch('someOtherAction', null, { root: true }) // -> 'someOtherAction'
commit('someMutation') // -> 'foo/someMutation'
commit('someMutation', null, { root: true }) // -> 'someMutation'
},
someOtherAction (ctx, payload) { ... }
}
}
}
```
## 在帶命名空間的模塊注冊全局 action
若需要在帶命名空間的模塊注冊全局 action,你可添加 root: true,并將這個 action 的定義放在函數 handler 中。例如:
```
{
actions: {
someOtherAction ({dispatch}) {
dispatch('someAction')
}
},
modules: {
foo: {
namespaced: true,
actions: {
someAction: {
root: true,
handler (namespacedContext, payload) { ... } // -> 'someAction'
}
}
}
}
}
```
帶命名空間的綁定函數
當使用 mapState, mapGetters, mapActions 和 mapMutations 這些函數來綁定帶命名空間的模塊時,寫起來可能比較繁瑣:
```
computed: {
...mapState({
a: state => state.some.nested.module.a,
b: state => state.some.nested.module.b
})
},
methods: {
...mapActions([
'some/nested/module/foo', // -> this['some/nested/module/foo']()
'some/nested/module/bar' // -> this['some/nested/module/bar']()
])
}
```
對于這種情況,你可以將模塊的空間名稱字符串作為第一個參數傳遞給上述函數,這樣所有綁定都會自動將該模塊作為上下文。于是上面的例子可以簡化為:
```
computed: {
...mapState('some/nested/module', {
a: state => state.a,
b: state => state.b
})
},
methods: {
...mapActions('some/nested/module', [
'foo', // -> this.foo()
'bar' // -> this.bar()
])
}
```
而且,你可以通過使用 createNamespacedHelpers 創建基于某個命名空間輔助函數。它返回一個對象,對象里有新的綁定在給定命名空間值上的組件綁定輔助函數:
```
import { createNamespacedHelpers } from 'vuex'
const { mapState, mapActions } = createNamespacedHelpers('some/nested/module')
export default {
computed: {
// 在 `some/nested/module` 中查找
...mapState({
a: state => state.a,
b: state => state.b
})
},
methods: {
// 在 `some/nested/module` 中查找
...mapActions([
'foo',
'bar'
])
}
}
```
- 內容介紹
- EcmaScript基礎
- 快速入門
- 常量與變量
- 字符串
- 函數的基本概念
- 條件判斷
- 數組
- 循環
- while循環
- for循環
- 函數基礎
- 對象
- 對象的方法
- 函數
- 變量作用域
- 箭頭函數
- 閉包
- 高階函數
- map/reduce
- filter
- sort
- Promise
- 基本對象
- Arguments 對象
- 剩余參數
- Map和Set
- Json基礎
- RegExp
- Date
- async
- callback
- promise基礎
- promise-api
- promise鏈
- async-await
- 項目實踐
- 標簽系統
- 遠程API請求
- 面向對象編程
- 創建對象
- 原型繼承
- 項目實踐
- Classes
- 構造函數
- extends
- static
- 項目實踐
- 模塊
- import
- export
- 項目實踐
- 第三方擴展庫
- immutable
- Vue快速入門
- 理解MVVM
- Vue中的MVVM模型
- Webpack+Vue快速入門
- 模板語法
- 計算屬性和偵聽器
- Class 與 Style 綁定
- 條件渲染
- 列表渲染
- 事件處理
- 表單輸入綁定
- 組件基礎
- 組件注冊
- Prop
- 自定義事件
- 插槽
- 混入
- 過濾器
- 項目實踐
- 標簽編輯
- 移動客戶端開發
- uni-app基礎
- 快速入門程序
- 單頁程序
- 底部Tab導航
- Vue語法基礎
- 模版語法
- 計算屬性與偵聽器
- Class與Style綁定
- 樣式與布局
- Box模型
- Flex布局
- 內置指令
- 基本指令
- v-model與表單
- 條件渲染指令
- 列表渲染指令v-for
- 事件與自定義屬性
- 生命周期
- 項目實踐
- 學生實驗
- 貝店商品列表
- 加載更多數據
- 詳情頁面
- 自定義組件
- 內置組件
- 表單組件
- 技術專題
- 狀態管理vuex
- Flyio
- Mockjs
- SCSS
- 條件編譯
- 常用功能實現
- 上拉加載更多數據
- 數據加載綜合案例
- Teaset UI組件庫
- Teaset設計
- Teaset使用基礎
- ts-tag
- ts-badge
- ts-button
- ta-banner
- ts-list
- ts-icon
- ts-load-more
- ts-segmented-control
- 代碼模版
- 項目實踐
- 標簽組件
- 失物招領客戶端原型
- 發布頁面
- 檢索頁面
- 詳情頁面
- 服務端開發技術
- 服務端開發環境配置
- Koajs快速入門
- 快速入門
- 常用Koa中間件介紹
- 文件上傳
- RestfulApi
- 一個復雜的RESTful例子
- 使用Mockjs生成模擬數據
- Thinkjs快速入門
- MVC模式
- Thinkjs介紹
- 快速入門
- RESTful服務
- RBAC案例
- 關聯模型
- 應用開發框架
- 服務端開發
- PC端管理界面開發
- 移動端開發
- 項目實踐
- 失物招領項目
- 移動客戶端UI設計
- 服務端設計
- 數據庫設計
- Event(事件)
- 客戶端設計
- 事件列表頁面
- 發布頁面
- 事件詳情頁面
- API設計
- image
- event
- 微信公眾號開發
- ui設計規范