Advertisement
jarocki_art

method save

Jul 4th, 2019
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. save() {
  2.   const params = new FormData()
  3.   const testimonial = this.testimonial
  4.  
  5.   for (const field in testimonial) {
  6.     params.append(field, testimonial[field])
  7.   }
  8.  
  9.   const request = this.id
  10.     ? this.$axios.put(`${this.loadUrl}/${this.id}`, params)
  11.     : this.$axios.post(this.loadUrl, params)
  12.  
  13.   request
  14.     .then(({ status }) => {
  15.       if (Number(status) === 200) this.success = 'Отзыв успешно обновлён'
  16.       if (Number(status) === 201) this.success = 'Отзыв успешно добавлен'
  17.       setTimeout(() => {
  18.         this.$router.push('/testimonials/')
  19.       }, 1000)
  20.     })
  21.     .catch(error => {
  22.       this.error = error + ''
  23.     })
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement