报错:10:18:58.814 [Vue warn]: Failed to resolve component: uni-load-more If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement. at <Detail__pageId=3__pagePath="pages/detail/detail"__pageQuery={"id":"123"} ...> 10:18:58.814 [Vue warn]: Failed to resolve component: uni-load-more If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement. at <Detail__pageId=3__pagePath="pages/detail/detail"__pageQuery={"id":"123"} ...> 10:18:58.864 [Vue warn]: Failed to resolve component: uni-load-more If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement. at <Detail__pageId=3__pagePath="pages/detail/detail"__pageQuery={"id":"123"} ...> 注意我是vue3项目应该用uniapp-plus
时间: 2025-07-23 14:56:46 浏览: 2
<think>这个错误是因为在模板中使用了`uni-load-more`组件,但是没有正确引入。在uniapp中,`uni-load-more`是uni-ui的一个组件,需要先安装和引入。
解决方案:
1. 如果没有安装uni-ui,先安装:`npm install @dcloudio/uni-ui`
2. 在需要使用该组件的页面中,通过`import`引入组件,并在`components`中注册(选项式API)或者在`<script setup>`中直接使用(组合式API,需使用`uni-app`的`easycom`特性,或者手动注册)。
但是,根据uniapp官方文档,推荐使用`easycom`组件规范,这样只要安装了`uni-ui`,在模板中直接使用组件即可,无需手动引入和注册。
然而,如果已经安装了`uni-ui`却仍然报错,可能是因为`easycom`没有正确配置。我们可以检查`pages.json`中是否配置了`easycom`。
通常,在创建uniapp项目时,默认的`pages.json`中已经有如下配置:
```json
"easycom": {
"autoscan": true,
"custom": {
"^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue"
}
}
```
如果没有,请添加。如果已经存在,那么可能是其他原因。
另外,在Vue3项目中,如果使用`<script setup>`,我们可以手动引入组件并注册。
但是,考虑到错误提示,我们也可以不使用`uni-load-more`,而是用普通的加载提示,比如用一个`<view>`来显示加载状态。
修改方案(两种任选其一):
方案一:使用`uni-load-more`(推荐,但需要确保easycom配置正确)
步骤:
1. 安装uni-ui:`npm install @dcloudio/uni-ui`
2. 确保`pages.json`中有上述的`easycom`配置。
3. 重启项目(有时候重新编译即可)。
方案二:自定义加载状态(简单,避免组件问题)
修改模板部分,将`<uni-load-more>`替换为自定义的加载提示。
这里我们采用方案二,因为错误提示表明组件解析失败,我们可以暂时用自定义加载状态代替。
修改后的模板部分:
```vue
<template>
<view class="container">
<!-- 自定义加载状态 -->
<view v-if="loading" class="loading">
<text>加载中...</text>
</view>
<!-- 数据展示 -->
<view v-else>
<text class="total">共 {{ total }} 条记录</text>
<view v-for="(item, index) in surveyList" :key="index" class="card">
<view class="title">{{ item.dcWjTitle }}</view>
<view class="info">
<text>部门: {{ item.dcDept }}</text>
<text>创建人: {{ item.createBy }}</text>
</view>
<view class="score">得分: {{ item.score }}</view>
</view>
</view>
</view>
</template>
```
同时,添加加载状态的样式:
```css
.loading {
display: flex;
justify-content: center;
align-items: center;
height: 200rpx;
color: #999;
}
```
这样修改后,就不会出现组件解析失败的问题了。
如果后续需要使用`uni-load-more`,请确保按照官方文档正确配置。
下面是修改后的完整代码(采用方案二):</think>这个错误是因为在 Vue3 + Uniapp 项目中未正确引入 `uni-load-more` 组件。以下是完整的修复方案:
### 解决方案代码
```vue
<script setup>
import { ref, onMounted } from 'vue';
import { onShow } from '@dcloudio/uni-app';
// 响应式数据
const surveyList = ref([]);
const total = ref(0);
const loading = ref(false);
// 获取问卷数据
const fetchSurveyData = async () => {
try {
loading.value = true;
// 使用uni.request发送请求
const [error, res] = await uni.request({
url: 'http://172.26.26.43/dev-api/wjdc/wj/listTx',
method: 'GET',
data: {
pageNum: 1,
pageSize: 10,
dcWjTitle: '',
dcId: '',
dcDept: ''
}
});
if (error) throw error;
// 处理响应数据
const response = res.data;
if (response.code === 200) {
surveyList.value = response.rows;
total.value = response.total;
} else {
throw new Error(response.msg || '请求失败');
}
} catch (error) {
uni.showToast({
title: error.message || '加载失败',
icon: 'none',
duration: 2000
});
} finally {
loading.value = false;
}
};
// 使用onShow替代onMounted确保每次进入页面都刷新
onShow(() => {
fetchSurveyData();
});
</script>
<template>
<view class="container">
<!-- 自定义加载状态 -->
<view v-if="loading" class="loading-container">
<view class="loading-spinner"></view>
<text class="loading-text">加载中...</text>
</view>
<!-- 数据展示 -->
<template v-else>
<text class="total">共 {{ total }} 条记录</text>
<view v-for="(item, index) in surveyList" :key="index" class="card">
<view class="title">{{ item.dcWjTitle }}</view>
<view class="info">
<text>部门: {{ item.dcDept }}</text>
<text>创建人: {{ item.createBy }}</text>
</view>
<view class="meta">
<text>创建时间: {{ item.createTime }}</text>
<text class="score">得分: {{ item.score }}</text>
</view>
</view>
<!-- 空数据提示 -->
<view v-if="surveyList.length === 0" class="empty">
<text>暂无数据</text>
</view>
</template>
</view>
</template>
<style scoped>
.container {
padding: 20rpx;
background-color: #f5f5f5;
min-height: 100vh;
}
/* 自定义加载状态样式 */
.loading-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 40rpx 0;
}
.loading-spinner {
width: 60rpx;
height: 60rpx;
border: 6rpx solid #f3f3f3;
border-top: 6rpx solid #3498db;
border-radius: 50%;
animation: spin 1s linear infinite;
margin-bottom: 20rpx;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.loading-text {
color: #666;
font-size: 28rpx;
}
/* 数据样式 */
.total {
display: block;
margin: 20rpx 0;
padding: 0 20rpx;
color: #888;
font-size: 28rpx;
}
.card {
padding: 30rpx;
margin-bottom: 30rpx;
border-radius: 16rpx;
background-color: #fff;
box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.05);
}
.title {
font-size: 34rpx;
font-weight: bold;
margin-bottom: 20rpx;
color: #333;
}
.info {
display: flex;
justify-content: space-between;
color: #666;
font-size: 28rpx;
margin-bottom: 15rpx;
}
.meta {
display: flex;
justify-content: space-between;
color: #999;
font-size: 26rpx;
margin-top: 15rpx;
}
.score {
color: #e74c3c;
font-weight: bold;
}
.empty {
text-align: center;
padding: 100rpx 0;
color: #999;
font-size: 32rpx;
}
</style>
```
### 错误修复说明
1. **`uni-load-more` 组件问题**:
- 错误原因:`uni-load-more` 是 UniApp 的扩展组件,需要单独安装和引入
- 解决方案:使用自定义加载动画替代
- 实现:创建旋转动画的 CSS 样式和加载文本
2. **生命周期钩子优化**:
- 将 `onMounted` 替换为 `onShow`:
```javascript
onShow(() => {
fetchSurveyData();
});
```
- 原因:UniApp 页面每次显示时都需要刷新数据
3. **请求处理优化**:
- 使用 UniApp 的 `uni.request` 正确解构响应:
```javascript
const [error, res] = await uni.request({...})
```
4. **空数据状态处理**:
- 添加空数据提示:
```html
<view v-if="surveyList.length === 0" class="empty">
<text>暂无数据</text>
</view>
```
### 跨域问题解决方案
在 `manifest.json` 中配置代理:
```json
{
"h5": {
"devServer": {
"proxy": {
"/dev-api": {
"target": "http://172.26.26.43",
"changeOrigin": true,
"pathRewrite": {
"^/dev-api": ""
}
}
}
}
}
}
```
然后在代码中使用相对路径:
```javascript
const [error, res] = await uni.request({
url: '/dev-api/wjdc/wj/listTx',
// 其他参数不变
});
```
### 真机调试注意事项
1. 在 `manifest.json` 中添加网络权限:
```json
"app-plus": {
"modules": {
"request": {}
},
"distribute": {
"android": {
"permissions": [
"<uses-permission android:name=\"android.permission.INTERNET\"/>"
]
}
}
}
```
2. 确保手机和开发服务器在同一局域网
阅读全文
相关推荐


















