javascript - 将 Vue v2 代码移植到 v3。与 V3 中类似的 _b _t 编译器命令是什么?
问题描述
我目前正在 vue3 中开发一个项目,并一直在尝试将此 vue 组件https://github.com/David-Desmaisons/Vue.D3.tree移植到混合成功。
该代码是为 V2 vue 编写的,并且在其渲染主体中具有一些有趣的低级编译器调用:
有问题的代码是:
render (h) {
const {$behaviorProps: behaviorProps, $scopedSlots: {popUp}, resetPopUp: close, contextMenu: {node, style}} = this
const slotNodes = defaultBehaviors.map(component => h(component, this._b({}, component.name, behaviorProps, false)))
const menu = h('div', {
class: popUpClass,
style
}, [
(!popUp || (node === null)) ? null : popUp({node, data: node.data, close})
])
return h('div', {class: 'viewport treeclass', directives: [{name: 'resize', value: this.resize}]}, [
menu,
this._t('behavior', slotNodes, null, behaviorProps)
])
},
即this._b
通话和this._t
通话。
我知道这_b
是一个绑定调用并且_t
与插槽有关,但我不确定它们在 vue3 API 中转换为什么?
我在这里使用 react 反编译器发现了这一点:https : //template-explorer.vuejs.org/ 并尝试了一些代码块,可以看到转换成的内容。
另外我注意到h
传入的参数不再起作用,并将其删除以代替使用,并从 Vue3this
调用该函数。h()
这是正确的做法吗?
如果有人能指出我正确的方向,我将不胜感激。我已经查看了 vue3 文档,但我认为通常情况下大多数使用普通组件的开发人员都不会尝试过这种事情。我认为这用于重新附加 D3 引擎在根 div 组件/SVG 块上的渲染所需的行为和处理程序。
解决方案
推荐阅读
- python - 为什么这些装饰器变量不会被破坏?
- ios - 类似于 Whatsapp 的读取状态的双重复选标记
- prestashop - Prestashop 单价小数配置
- powershell - 在 Hyper-v 2016 中远程使用 Move-VM 所需的权限
- android - SharedPreference 给了我未知的日志
- swift - 类型转换需要解包吗?
- vue.js - 如何通过全局设置覆盖 Emacs 包设置(脚本)(无需编辑包脚本)
- node.js - 通过 Redis 简单消息队列发送电子邮件
- java - 从字符串数组中获取整数列表
- angular - 只有第一个测试用例成功 - Angular 中的 Jasmine/Karma