[Vuejs]-How to change parent value with using child value VUE JS

0👍

You have to use vuejs emits: https://vuejs.org/guide/components/events.html.

Try somthing like this on your child component:

export default {
   props: {
    title: String,
    price: Number,
  },
  data(){
   return{
      count:0,
      totalOfItem: 0
   }
  },
  emits: ['onClickChild'],
  setup(props, emit) {
   function increasePrice(){
      this.count -= 1
      this.totalOfItem = this.count * this.price
      emit('onClickChild', this.totalOfItem)
   }

   function decreasePrice(){
      this.count += 1
      this.totalOfItem = this.count * this.price
      emit('onClickChild', this.totalOfItem)
   }
   
   return {
      increasePrice,
      decreasePrice,
   }
  }
}

Leave a comment