Header Ads

Header ADS

Vue js 3 emit use


  //here we used this code to read data without page refresh from DB after insert.

1.npm install mitt


2.in app.js import these code



// window.Reload = new Vue();
 import mitt from 'mitt';

 // Create an event bus
const emitter = mitt();

// Provide the event bus to all components
app.config.globalProperties.$Reload = emitter;
app.provide('emitter', emitter);

//in vue components,
addToCart(id)
    {
      axios.post('/api/addtocart/'+id)
      .then(() => {

        this.$Reload.emit("afterAdd");

        Toast.fire({
            icon: "success",
            title: "successfully done Pos Product insert"
        });

      })
      .catch()

    },

//created method
  created(){
   
    this.cartProducts();

    this.$Reload.on("afterAdd", ()=>{
      this.cartProducts();
    });

  },

No comments

Theme images by fpm. Powered by Blogger.