uni-app app.js错误 TypeError: Cannot read property 'call' of undefined
uni-app app.js错误 TypeError: Cannot read property ‘call’ of undefined
产品分类:
uniapp/小程序/微信
PC开发环境操作系统:
Windows
PC开发环境操作系统版本号:
w10
HBuilderX类型:
正式
HBuilderX版本号:
3.2.12
第三方开发者工具版本号:
1.05.21
基础库版本号:
2.20.2
项目创建方式:
HBuilderX
示例代码:
<template>
<view class="Index-page">
<!-- 访客角色(首页) -->
<home-visitor
v-if="!userInfo.userType || userInfo.userType === '10'"
recommendList="unitList"
>Loading="Loading"
/>
<!-- 客户角色(首页) -->
<home-client v-if="userInfo.userType === '20'" :recommendList="unitList" :Loading="Loading" />
<view class="cu-load" :class="!isLoad ? 'loading' : 'over'"></view>
</view>
</template>
操作步骤:
<template>
<view class="Index-page">
<!-- 访客角色(首页) -->
<home-visitor
v-if="!userInfo.userType || userInfo.userType === '10'"
recommendList="unitList"
>Loading="Loading"
/>
<!-- 客户角色(首页) -->
<home-client v-if="userInfo.userType === '20'" :recommendList="unitList" :Loading="Loading" />
<view class="cu-load" :class="!isLoad ? 'loading' : 'over'"></view>
</view>
</template>
预期结果:
<template>
<view class="Index-page">
<!-- 访客角色(首页) -->
<home-visitor
v-if="!userInfo.userType || userInfo.userType === '10'"
recommendList="unitList"
>Loading="Loading"
/>
<!-- 客户角色(首页) -->
<home-client v-if="userInfo.userType === '20'" :recommendList="unitList" :Loading="Loading" />
<view class="cu-load" :class="!isLoad ? 'loading' : 'over'"></view>
</view>
</template>
实际结果:
<template>
<view class="Index-page">
<!-- 访客角色(首页) -->
<home-visitor
v-if="!userInfo.userType || userInfo.userType === '10'"
recommendList="unitList"
>Loading="Loading"
/>
<!-- 客户角色(首页) -->
<home-client v-if="userInfo.userType === '20'" :recommendList="unitList" :Loading="Loading" />
<view class="cu-load" :class="!isLoad ? 'loading' : 'over'"></view>
</view>
</template>
bug描述:
app.js错误: TypeError: Cannot read property ‘call’ of undefined
通过v-if判断进入小程序角色状态;显示不同组件,很大概率会抛出app.js错误,然后就白屏,需要重新运行项目才可以解决,为什么会出现这种情况呢?而且发生的概率非常大,浪费很多时间。


更多关于uni-app app.js错误 TypeError: Cannot read property 'call' of undefined的实战教程也可以访问 https://www.itying.com/category-93-b0.html
我这段时间也是经常碰到这个,好难啊
更多关于uni-app app.js错误 TypeError: Cannot read property 'call' of undefined的实战教程也可以访问 https://www.itying.com/category-93-b0.html
应该是,我现在没有提示了
这个错误通常是由于组件注册或引入问题导致的。从你的代码来看,问题可能出现在以下几个方面:
-
组件未正确注册或引入:
home-visitor和home-client组件可能没有在页面中正确导入或注册。请检查是否在<script>标签中正确导入了这两个组件。 -
组件路径问题:确保组件路径正确,特别是在Windows环境下路径大小写敏感问题。
-
组件生命周期冲突:当使用
v-if切换组件时,如果组件内部有异步操作或生命周期钩子执行异常,可能导致call错误。
解决方案:
- 检查组件导入:
import homeVisitor from '@/components/home-visitor.vue'
import homeClient from '@/components/home-client.vue'
export default {
components: {
homeVisitor,
homeClient
}
}
-
使用
v-show替代v-if:如果组件切换频繁,考虑使用v-show而不是v-if,避免组件的频繁销毁和重建。 -
确保数据初始化:在
data中确保userInfo有默认值:
data() {
return {
userInfo: {},
// 其他数据...
}
}


