[Vuejs]-Vue 2 updates and prints after loading the page

0👍

There are some things you can try to make this work. Since there’s no working jsFiddle for this problem, I can only suggest you try these.

  • Try converting the created hook into an async function and await the axios call.

    async created() {
        await axios.get(`/api/pickUp/${no}/preview`, {
        params: {
          code,
        },
      }).then((res) => {
        this.preview = true;
        this.shipment = res.data.data.shipments;
        this.selectedShipment = res.data.data.shipments;
        this.price = res.data.data.price;
      });

  • Try moving the updated hook code inside .then in created hook.

    async created() {
      await axios.get(`/api/pickUp/${no}/preview`, {
        params: {
          code,
        },
      }).then((res) => {
        this.preview = true;
        this.shipment = res.data.data.shipments;
        this.selectedShipment = res.data.data.shipments;
        this.price = res.data.data.price;
        this.$nextTick(() => {
        window.print();
        });
      });
    },

Leave a comment