natec1991

update.js

Aug 21st, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Multiselect from "vue-multiselect";
  2. import __ from 'lodash';
  3.  
  4. export default {
  5.     name: 'resume-update',
  6.     props: ['resume'],
  7.     components: {
  8.         Multiselect
  9.     },
  10.    
  11.     data: () => ({
  12.         form: {
  13.             name: '',
  14.             level: '',
  15.             salary: '',
  16.             experience: '',
  17.             education: [],
  18.             employment: []
  19.         },
  20.         submitted: {
  21.             form: false,
  22.             destroy: false,
  23.             restore: false
  24.         },
  25.         errors: []
  26.     }),
  27.  
  28.     methods: {
  29.         update(e) {
  30.             this.submitted.form = true;
  31.             axios.put(e.target.action, this.form).then(response => {
  32.                 this.resume = response.data.data
  33.                 this.submitted.form = false;
  34.             }).catch(error => {
  35.                 if (error.response) {
  36.                     this.errors = error.response.data.errors;
  37.                 }
  38.                 this.submitted.form = false;
  39.             });
  40.         },
  41.         destroy() {
  42.             this.submitted.destroy = true;
  43.             axios.delete(this.resume.routes.destroy).then(response => {
  44.                 this.resume = response.data.data;
  45.                 this.submitted.destroy = false;
  46.             }).catch(error => {
  47.                 this.submitted.destroy = false;
  48.             })
  49.         },
  50.         restore() {
  51.             this.submitted.restore = true;
  52.             axios.post(this.resume.routes.restore).then(response => {
  53.                 this.resume = response.data.data;
  54.                 this.submitted.restore = false;
  55.             }).catch(error => {
  56.                 this.submitted.restore = false;
  57.             })
  58.         },
  59.         reset() {
  60.             for (const prop of Object.getOwnPropertyNames(this.form)) {
  61.                 delete this.form[prop];
  62.             }
  63.         }
  64.     },
  65.  
  66.     watch: {
  67.         resume: function() {
  68.             this.form = this.resume;
  69.         },
  70.     },
  71.  
  72.     created() {
  73.         this.form = __.cloneDeep(this.resume);
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment