1、报错1:
Uncaught (in promise) TypeError: Cannot read property '__asyncLoader' of undefined
2、报错2:
TypeError: Cannot read properties of null (reading 'emitsOptions')
使用tsx类似如下
<div>
{arr.map(it => <OtherComponent></OtherComponent>}
</div>
通过控制arr内容自动生成列表
然而列表能正常插入dom。置空时就报上述错误。
排查
经过若干尝试(什么vue-router defineAsyncComponent均无效。)
范围缩小在OtherComponent 组件。
分块注释法排查[doge]。。。
结果
jsx中使用compouted值,没有.value
OtherComponent 示意代码
defineComponent({
setup(){
let a = computed(() => ...)
return () => <div>
{ a } // 导致报错
{ a.value } // 正确
</div>
}
})
总结
computed 的变量,在jsx中使用时未.value 导致。
文章讨论了在使用Vue.js和tsx时遇到的两个TypeError。当尝试通过arr.map生成列表时,如果arr为空,会导致Cannotreadproperty__asyncLoaderofundefined的错误。另外,定义在OtherComponent组件中的computed属性在jsx中使用时,未加.value会抛出错误。解决方案是确保在jsx中引用computed属性时添加.value。

6464

被折叠的 条评论
为什么被折叠?



