[Vuejs]-How to initialize a data property to a prop object property in Vue JS

0👍

I’ve used the beforeCreate hook to set the availableQuantity. The adjusted code looks something like this:

<template>
  <div>
    <div>Initial Quantity  {{item.quantity}}</div>
    <div>Available Quantity  {{availableQuantity}}</div>
  </div>
</template>
<script>
  export default {
    name: "comp1",
    props: ["item"]
    data: function() {
      return {
        availableQuantity: 0
      }
    },
    beforeCreate() {
      this.availableQuantity = this.item.quantity;
    }
  }
<script>

Leave a comment