传任意参数的能力
vue 的父组件传值给子组件是传引用。子组件拿到的参数是 === 传入参数。微信小程序的传值是 JSON 序列化拷贝的传值。子组件拿到的是 JSON.parse(JSON.stringify(val))。
意味着传不了 function,callback,传不了 map/set,传不了任意不能 JSON 序列化回来的东西。
不支持 v-bind 和 $attrs
该特性参见:https://www.jianshu.com/p/ce8ca875c337
$attrs 类比 javascript 就是
function SomeComponet() {
console.log(arguments):
}
SomeComponent(1)
SomeComponent(2, 'abc')
无论你传什么,arguments 都能全部捕获。
v-bind 类比 javascript 就是
function SomeComponent(a, b) {
}
SomeComponent.call(someThis, aVal, bVal);
SomeComponent.apply(someThis, [aVal, bVal]);
也就是通过 call/apply 调用变长参数列表函数的能力。
v-bind="$attrs",这个就是 apply(someThis, arguments)。透传所有参数给另外一个组件。
不支持 <component :is="">
vue 可以用名字动态调用组件。微信小程序即便有抽象节点,也不能达到 component is 的效果。remax / kbone 用 template 模拟类似的效果,但是因为不支持 v-bind 和 $attrs,只能静态生成一堆 template。
https://raw.githubusercontent.com/Tencent/kbone/eaa30c93b58136ceb22038d9c6e423bf5bf69ccd/packages/miniprogram-element/src/template/inner-component.wxml
不支持带参数的 slot
<current-user #default="{ user }">
{{ user.firstName }}
</current-user>
vue 传入的 slot,是可以从被调组件那里拿到回调的参数的。这个类比 javascript 就是
const localProps;
const mySlot = (slotProps) => {
// ... use localProps and slotProps
}
SomeComponent(mySlot);
传入的 slot 就是一个绑定了当前作用域上变量的闭包。这个闭包同时,又可以从参数,从被调的 SomeComponent 拿到回调的 slotProps。
微信小程序的 slot,只能拿到 localProps,拿不到 slotProps。
微信小程序的抽象节点,只能拿到 slotProps,拿不到 localProps。
微信为啥觉得“闭包”这么有用的功能是不必须的呢? 这是官方的解释: 需求:更强大的slot | 微信开放社区
结论
缺了啥,缺心眼。
好消息是,以上所有缺陷都可以通过 AOT 的方式抹平。