vue3项目中使用vue-pdf 报错TypeError: h is not a function 报错Vue is not a constructor?-灵析社区

577739990

前提:一不小心搭建了vue3项目,vue-pdf最新版本为4.2.0,不是针对vue3构建的 问题1:TypeError: h is not a function ![图片](https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241129/2f5529e6cdc9c1d58bd282ba55c87c9d.png) 原因:h在vue3的render函数中不再以参数形式出现,需要手动导入 解决:将vue-pdf中的render: function (h)替换为render: function (), 然后手动导入import { h } from 'vue' 在vue-pdf的依赖vue-resize-sensor中同样将render: function(create)替换为render: function(), 然后手动导入import { h as create } from 'vue' 问题2:ReferenceError: $emit is not defined ![图片](https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241129/d8e3d779beadfc88ae8829ea09268b2c.png) 解决:npm install vue-happy-bus --save, 然后手动导入import { $on, $emit } from 'vue-happy-bus'. this.$on替换为$on,this.$emit替换为$emit 问题3:修改了vue-pdf和vue-resize-sensor中的源码如何上传到自己的项目 解决:npm install patch-package --save-dev, npx patch-package vue-pdf npx patch-package vue-resize-sensor 修改package.json "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", "lint": "vue-cli-service lint", "postinstall": "patch-package"//增加这个命令 }, 遗留问题:引入vue-happy-bus报错Vue is not a constructor

阅读量:12

点赞量:0

问AI
"https://segmentfault.com/a/1190000039858927" (https://segmentfault.com/a/1190000039858927)