File tree Expand file tree Collapse file tree 2 files changed +29
-12
lines changed
Expand file tree Collapse file tree 2 files changed +29
-12
lines changed Original file line number Diff line number Diff line change @@ -60,25 +60,19 @@ import { CATEGORIES } from '../../../consts';
6060
6161export default {
6262 name: ' accounts-create-edit-view' ,
63+ props: [' accountId' ],
6364
6465 data : () => {
6566 return {
6667 categories: CATEGORIES ,
67- selectedAccount : {} ,
68- editing : false
68+ editing : false ,
69+ selectedAccount : {}
6970 };
7071 },
7172
7273 mounted () {
73- if (' accountId' in this .$route .params ) {
74- this .loadAccounts ().then (() => {
75- let selectedAccount = this .getAccountById (this .$route .params .accountId );
76- if (selectedAccount) {
77- this .editing = true ;
78- this .selectedAccount = Object .assign ({}, selectedAccount);
79- }
80- // TODO: the object does not exist, how do we handle this scenario?
81- });
74+ if (this .accountId ) {
75+ this .loadAccount ();
8276 }
8377 },
8478
@@ -108,13 +102,35 @@ export default {
108102
109103 processSave () {
110104 this .editing ? this .saveAccount () : this .saveNewAccount ();
105+ },
106+
107+ loadAccount () {
108+ let vm = this ;
109+ this .loadAccounts ().then (() => {
110+ let selectedAccount = vm .getAccountById (vm .accountId );
111+ if (selectedAccount) {
112+ vm .editing = true ;
113+ vm .selectedAccount = Object .assign ({}, selectedAccount);
114+ }
115+ // TODO: the object does not exist, how do we handle this scenario?
116+ });
111117 }
112118 },
113119
114120 computed: {
115121 ... mapGetters ([
116122 ' getAccountById'
117123 ])
124+ },
125+
126+ watch: {
127+ accountId (newId ) {
128+ if (newId) {
129+ this .loadAccount ();
130+ }
131+ this .editing = false ;
132+ this .selectedAccount = {};
133+ }
118134 }
119135};
120136 </script >
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ export default [
1414 {
1515 path : '/accounts/:accountId/update' ,
1616 component : components . CreateUpdateAccount ,
17- name : 'updateAccount'
17+ name : 'updateAccount' ,
18+ props : true
1819 }
1920] ;
You can’t perform that action at this time.
0 commit comments