用Vue 打印repx格式模板
时间: 2023-07-12 11:33:47 浏览: 66
首先,你需要安装一个Vue插件,名为vue-html-to-paper。你可以在你的Vue项目中使用npm安装它:
```
npm install vue-html-to-paper --save
```
安装完成后,你需要在main.js中引入它并注册:
```javascript
import VueHtmlToPaper from 'vue-html-to-paper';
Vue.use(VueHtmlToPaper);
```
接下来,在你的Vue组件中,你可以使用指令v-html-to-paper来打印你的repx格式模板:
```html
<template>
<div>
<div ref="printContent">
<!-- 这里放你的repx格式模板 -->
</div>
<button @click="print">打印</button>
</div>
</template>
<script>
export default {
methods: {
print() {
this.$htmlToPaper(this.$refs.printContent, {
name: '_blank',
specs: ['fullscreen=yes', 'titlebar=yes', 'scrollbars=yes'],
styles: [
'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css',
'https://unpkg.com/kidlat-css/css/kidlat.css'
]
});
}
}
}
</script>
```
在上面的代码中,当你点击打印按钮时,它会将div中的内容打印出来。你可以通过配置项来控制打印的窗口名称、窗口样式等等。在styles数组中,你可以引入你需要的CSS文件来控制打印的样式。
希望这可以帮助到你!