After reviewing the source code on https://github.com/mycurelabs/vue-html-to-paper/blob/master/src/index.js, it seems that there is no built-in variable to handle a specific task (which would be helpful; perhaps a pull request could address this?). However, we can create our own solution.
To do so, add a new variable called printing
in the data
section of your component:
data() {
return {
printing: false,
}
},
Update your template to utilize this new variable:
<template>
<div id="printThis">
<h1> My title </h1>
<button v-show="!printing"> I WANT TO DISPLAY THIS BUTTON IN PRINT!!! </button>
<p> My paragraph </p>
</div>
</template>
(You can also use v-if instead, each method has its advantages and disadvantages.)
Next, modify the method call to the plugin within a custom method to toggle the variable on and off. Follow the plugin documentation's callback instructions to reset the variable:
print(){
this.printing = true;
const options = null; // Customize as needed per https://randomcodetips.com/vue-html-to-paper/
this.$htmlToPaper('printThis', options, () => {
this.printing = false;
});
}
And that's it.
It might be worth considering developing a more efficient plugin to achieve the same functionality. Implementing a promise-based approach or defining lifecycle events for print success or failure could enhance the process significantly.