文章詳情頁
javascript - 一個vuex的問題
瀏覽:118日期:2023-02-10 13:08:59
問題描述
如下,如何獲取children然后更新到father.children中,頁面就可以列表展示了
state: { father: [{ name: ’wang’, children: []} ]}action: { getChildren(fatherId).then(children => {// 獲得children,如何更新到father.children中 });}
問題解答
回答1:state: { father: [{ name: ’wang’, children: []} ]}, mutations:{updateChildren(state,children){ state.father[0].children = children;}},actions: { updateChildren({commit}){getChildren(fatherId).then(children => { // 獲得children,如何更新到father.children中 commit('updateChildren',children );}); }}
大概這樣吧,去看看文檔吧
標簽:
JavaScript
相關文章:
1. android - 分享到微信,如何快速轉換成字節數組2. 解決Android webview設置cookie和cookie丟失的問題3. javascript - 能否讓vue-cli的express修改express重啟服務4. angular.js - Beego 與 AngularJS的模板格式沖突,該怎么解決?5. node.js - npm一直提示proxy有問題6. 請問連接文件怎么寫7. 網頁爬蟲 - Python爬蟲入門知識8. mysql怎么多表刪除啊?9. javascript - 有沒有iOS微信中可以在背景播放視頻的方法?10. python - flask template file not found
排行榜
