File tree Expand file tree Collapse file tree 5 files changed +15
-15
lines changed Expand file tree Collapse file tree 5 files changed +15
-15
lines changed Original file line number Diff line number Diff line change @@ -57,10 +57,10 @@ Example testing an async action:
57
57
// actions.js
58
58
import shop from ' ../api/shop'
59
59
60
- export const getAllProducts = ({ dispatch }) => {
61
- dispatch (' REQUEST_PRODUCTS' )
60
+ export const getAllProducts = ({ commit }) => {
61
+ commit (' REQUEST_PRODUCTS' )
62
62
shop .getProducts (products => {
63
- dispatch (' RECEIVE_PRODUCTS' , products)
63
+ commit (' RECEIVE_PRODUCTS' , products)
64
64
})
65
65
}
66
66
```
Original file line number Diff line number Diff line change @@ -57,10 +57,10 @@ Exemple de test d'une action asynchrone :
57
57
// actions.js
58
58
import shop from ' ../api/shop'
59
59
60
- export const getAllProducts = ({ dispatch }) => {
61
- dispatch (' REQUEST_PRODUCTS' )
60
+ export const getAllProducts = ({ commit }) => {
61
+ commit (' REQUEST_PRODUCTS' )
62
62
shop .getProducts (products => {
63
- dispatch (' RECEIVE_PRODUCTS' , products)
63
+ commit (' RECEIVE_PRODUCTS' , products)
64
64
})
65
65
}
66
66
```
Original file line number Diff line number Diff line change @@ -57,10 +57,10 @@ describe('mutations', () => {
57
57
// actions.js
58
58
import shop from ' ../api/shop'
59
59
60
- export const getAllProducts = ({ dispatch }) => {
61
- dispatch (' REQUEST_PRODUCTS' )
60
+ export const getAllProducts = ({ commit }) => {
61
+ commit (' REQUEST_PRODUCTS' )
62
62
shop .getProducts (products => {
63
- dispatch (' RECEIVE_PRODUCTS' , products)
63
+ commit (' RECEIVE_PRODUCTS' , products)
64
64
})
65
65
}
66
66
```
Original file line number Diff line number Diff line change @@ -57,10 +57,10 @@ describe('mutations', () => {
57
57
// actions.js
58
58
import shop from ' ../api/shop'
59
59
60
- export const getAllProducts = ({ dispatch }) => {
61
- dispatch (' REQUEST_PRODUCTS' )
60
+ export const getAllProducts = ({ commit }) => {
61
+ commit (' REQUEST_PRODUCTS' )
62
62
shop .getProducts (products => {
63
- dispatch (' RECEIVE_PRODUCTS' , products)
63
+ commit (' RECEIVE_PRODUCTS' , products)
64
64
})
65
65
}
66
66
```
Original file line number Diff line number Diff line change @@ -57,10 +57,10 @@ Actions 应对起来略微棘手,因为它们可能需要调用外部的 API
57
57
// actions.js
58
58
import shop from ' ../api/shop'
59
59
60
- export const getAllProducts = ({ dispatch }) => {
61
- dispatch (' REQUEST_PRODUCTS' )
60
+ export const getAllProducts = ({ commit }) => {
61
+ commit (' REQUEST_PRODUCTS' )
62
62
shop .getProducts (products => {
63
- dispatch (' RECEIVE_PRODUCTS' , products)
63
+ commit (' RECEIVE_PRODUCTS' , products)
64
64
})
65
65
}
66
66
```
You can’t perform that action at this time.
0 commit comments