Having trouble retrieving data from the API using Vue JS and printing the page? After fetching the data, some elements may not render completely when trying to print, resulting in blank data being displayed. While using a setTimeout function may work for some clients, it is not a perfect solution as it may require setting a longer waiting timeout to ensure all clients can print successfully. This workaround is not ideal.
methods: {
getData() {
axios.get('/api/sale/receipt/' + this.$route.params.uuid).then((res) => {
this.sale = res.data
if(this.sale.customer == null) {
this.sale.customer = {}
}
$('.main-loader').hide();
// setTimeout(function() {
window.print();
window.close();
// }, 2000);
}).catch((res) => {
});
}
},
After the elements have rendered, the print option will pop up. Thank you!