Javascript vue html与Vue3一起打印

Javascript vue html与Vue3一起打印,javascript,vue.js,printing,vuejs3,Javascript,Vue.js,Printing,Vuejs3,我想尝试vue html到纸张,并根据文档进行了最简单的设置。不过我正在使用Vue3 npm install vue-html-to-paper 和我的组件: <template> <div> <div id="example"> Hello World </div> <button @click="print"> Print <

我想尝试vue html到纸张,并根据文档进行了最简单的设置。不过我正在使用Vue3

npm install vue-html-to-paper
和我的组件:

<template>
  <div>
    <div id="example">
      Hello World
    </div>

    <button @click="print">
      Print
    </button>
  </div>
</template>

<script>
export default {
  name: "my_component",

  methods: {
    print: function() {
      this.$htmlToPaper("example");
    },
  },
</script>
[...]

你好,世界
印刷品
导出默认值{
名称:“我的_组件”,
方法:{
打印:函数(){
本文件(“示例”);
},
},
[...]
在dev上,我在控制台中遇到一个错误,
[…]无法设置未定义[…]的属性“$htmlToPaper”
。我做错了什么

谢谢,我很感谢你给我一个提示。

It
Vue.prototype
因此,除非已经修复,否则它将无法与Vue 3一起工作。如果你想自己修复它,你可以进行回购

要执行此操作,请更换此❌:

install(Vue,选项={}){
Vue.prototype.$htmlToPaper=(el,localOptions,cb=()=>true)=>{
用这个✅ 适用于Vue 2和Vue 3:

install(_i,options={}){
设globals=_i.prototype | | u i.config.globalProperties;
全局。$htmlToPaper=(el,localOptions,cb=()=>true)=>{

使用Vue 3安装插件时,请遵循但替换
Vue。使用
应用程序使用
。使用

谢谢Dan,你是救命恩人。也找到了这个
<template>
  <div>
    <div id="example">
      Hello World
    </div>

    <button @click="print">
      Print
    </button>
  </div>
</template>

<script>
export default {
  name: "my_component",

  methods: {
    print: function() {
      this.$htmlToPaper("example");
    },
  },
</script>
[...]