3636 </vuetify-resource >
3737 </v-container >
3838</template >
39+
3940<script >
40- import FormDataValues from ' ./../mixins/formDataValues' ;
4141import axios from ' ../api/implementation/app' ;
4242import VuetifyResource from ' @kingscode/vuetify-resource' ;
4343
4444export default {
4545 name: ' Resource' ,
4646 components: {VuetifyResource},
47- mixins: [FormDataValues],
4847 data () {
4948 return {
5049 createForm: {values: {}},
@@ -54,6 +53,10 @@ export default {
5453 };
5554 },
5655 props: {
56+ modelType: {
57+ type: Function ,
58+ required: false ,
59+ },
5760 tableContent: {
5861 type: Array ,
5962 required: true ,
@@ -151,7 +154,15 @@ export default {
151154 return new Promise ((resolve ) => {
152155 axios .get ((this .showResourceUri || this .resourceUri ) + ' /' + id)
153156 .then ((response ) => {
154- let item = response .data .data ;
157+ let item;
158+
159+ if (this .modelType ) {
160+ item = new this.modelType ();
161+ item .mapResponse (response .data .data );
162+ } else {
163+ item = response .data .data ;
164+ }
165+
155166 resolve ({
156167 item,
157168 });
@@ -168,7 +179,12 @@ export default {
168179 if (this .createForm .valid ) {
169180 this .createHandler (this .createForm .values )
170181 .then ((response ) => {
171- this .createForm .values = {};
182+ if (this .modelType ) {
183+ this .createForm .values = new this.modelType ();
184+ } else {
185+ this .createForm .values = {};
186+ }
187+
172188 if (typeof this .afterCreate === ' function' ) {
173189 this .afterCreate (response .data ).then (() => {
174190 resolve ();
@@ -196,6 +212,7 @@ export default {
196212 process .nextTick (() => {
197213 if (this .updateForm .valid ) {
198214 this .updateForm .values .id = selected[0 ].id ;
215+
199216 this .updateHandler (this .updateForm .values )
200217 .then ((response ) => {
201218 if (typeof this .afterUpdate === ' function' ) {
@@ -243,7 +260,13 @@ export default {
243260 this .beforeOpenUpdate (selected);
244261 return ;
245262 }
246- this .updateForm .values = selected[0 ];
263+
264+ if (this .modelType ) {
265+ this .updateForm .values = new this.modelType ();
266+ this .updateForm .values .mapResponse (selected[0 ]);
267+ } else {
268+ this .updateForm .values = {};
269+ }
247270 },
248271 },
249272};
0 commit comments