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:
5757// actions.js
5858import shop from ' ../api/shop'
5959
60- export const getAllProducts = ({ dispatch }) => {
61- dispatch (' REQUEST_PRODUCTS' )
60+ export const getAllProducts = ({ commit }) => {
61+ commit (' REQUEST_PRODUCTS' )
6262 shop .getProducts (products => {
63- dispatch (' RECEIVE_PRODUCTS' , products)
63+ commit (' RECEIVE_PRODUCTS' , products)
6464 })
6565}
6666```
Original file line number Diff line number Diff line change @@ -57,10 +57,10 @@ Exemple de test d'une action asynchrone :
5757// actions.js
5858import shop from ' ../api/shop'
5959
60- export const getAllProducts = ({ dispatch }) => {
61- dispatch (' REQUEST_PRODUCTS' )
60+ export const getAllProducts = ({ commit }) => {
61+ commit (' REQUEST_PRODUCTS' )
6262 shop .getProducts (products => {
63- dispatch (' RECEIVE_PRODUCTS' , products)
63+ commit (' RECEIVE_PRODUCTS' , products)
6464 })
6565}
6666```
Original file line number Diff line number Diff line change @@ -57,10 +57,10 @@ describe('mutations', () => {
5757// actions.js
5858import shop from ' ../api/shop'
5959
60- export const getAllProducts = ({ dispatch }) => {
61- dispatch (' REQUEST_PRODUCTS' )
60+ export const getAllProducts = ({ commit }) => {
61+ commit (' REQUEST_PRODUCTS' )
6262 shop .getProducts (products => {
63- dispatch (' RECEIVE_PRODUCTS' , products)
63+ commit (' RECEIVE_PRODUCTS' , products)
6464 })
6565}
6666```
Original file line number Diff line number Diff line change @@ -57,10 +57,10 @@ describe('mutations', () => {
5757// actions.js
5858import shop from ' ../api/shop'
5959
60- export const getAllProducts = ({ dispatch }) => {
61- dispatch (' REQUEST_PRODUCTS' )
60+ export const getAllProducts = ({ commit }) => {
61+ commit (' REQUEST_PRODUCTS' )
6262 shop .getProducts (products => {
63- dispatch (' RECEIVE_PRODUCTS' , products)
63+ commit (' RECEIVE_PRODUCTS' , products)
6464 })
6565}
6666```
Original file line number Diff line number Diff line change @@ -57,10 +57,10 @@ Actions 应对起来略微棘手,因为它们可能需要调用外部的 API
5757// actions.js
5858import shop from ' ../api/shop'
5959
60- export const getAllProducts = ({ dispatch }) => {
61- dispatch (' REQUEST_PRODUCTS' )
60+ export const getAllProducts = ({ commit }) => {
61+ commit (' REQUEST_PRODUCTS' )
6262 shop .getProducts (products => {
63- dispatch (' RECEIVE_PRODUCTS' , products)
63+ commit (' RECEIVE_PRODUCTS' , products)
6464 })
6565}
6666```
You can’t perform that action at this time.
0 commit comments