Getting Started
Prerequisites
- Vue.js 3.x
Installation
shell
$ npm install vue-to-print --save
shell
$ pnpm add vue-to-print
shell
$ yarn add vue-to-print
Usage
You can use vue-to-print
by combining the Composition API (useVueToPrint
).
The only required parameter is content
, which is a ref
pointing to the HTML element you want to print.
vue
<script setup lang="ts">
import { useVueToPrint } from "vue-to-print";
import { ref } from "vue";
const componentRef = ref();
const { handlePrint } = useVueToPrint({
content: componentRef,
documentTitle: "AwesomeFileName",
});
</script>
<template>
<button @click="handlePrint">Print</button>
<div ref="componentRef">
<h1>Hello, world!</h1>
</div>
</template>