stefanpandele

props to data

Jan 24th, 2021
691
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.     <div>
  3.         <p>{{category}}</p> //afisa obiectul de categorie OK
  4.         <p>{{localCategory}}</p> //afisa obiect gol {}
  5.     </div>
  6. </template>
  7.  
  8. props: {
  9.     category: {
  10.         type: Object,
  11.         required: true
  12.     }
  13. }
  14. data () {
  15.     return {
  16.         //localCategory: Object.assign({}, this.category)
  17.         localCategory: JSON.parse(JSON.stringify(this.category))
  18.     }
  19. }
  20.  
  21. //partinte
  22. data() {
  23.     return {
  24.         category: {}
  25.     }
  26. },
  27. created() {
  28.     this.$store.dispatch('category/fetchCategory', this.$route.params.id)
  29.     .then((response) => {
  30.        this.category = response
  31.     })
  32.     .catch(error => {
  33.        console.log(error)
  34.     })
  35. }
  36.  
RAW Paste Data