mycurelabs / vue-html-to-paper

Vue mixin for paper printing html elements.
MIT License
298 stars 101 forks source link

Vue 3 composition API #127

Open prasetyo-jeanu opened 1 year ago

prasetyo-jeanu commented 1 year ago

I cant access htmlToPaper in vue 3 composition API

async function print() {
    row.value = rows.value[2];
    htmlToPaper("print"); // cant access this
}
TrumanWwW commented 1 month ago

@prasetyo-jeanu you can use provide/inject to access it, I've try it

/* your main.js*/
...
app.provide("$htmlToPaper", app.config.globalProperties.$htmlToPaper);
...
<script>
/*where you want to print*/
...
const $htmlToPaper = inject("$htmlToPaper");

const printThis = () => {
  $htmlToPaper("printArea");
};
</script>

It works !

ps: getCurrentInstance is deprecated in latest Vue version