uni-app + Vue3 编译的抖音小程序 onPullDownRefresh 不执行

uni-app + Vue3 编译的抖音小程序 onPullDownRefresh 不执行

项目信息
产品分类 uniapp/小程序/字节跳动
PC开发环境操作系统 Mac
PC开发环境操作系统版本号 macOS 14.1 (23B74) ; node v21.6.2
第三方开发者工具版本号 Version: 4.3.1 OS: darwin DeviceId: df67e4e5-80e5-567b-9dba-cae744ba60f7 BuildId: 12197063 Electron: 25.9.1 Chrome: 114.0.5735.289 Node.js: 18.15.0 V8: 11.4.183.29-electron.0
基础库版本号 3.43.0.12
项目创建方式 CLI
CLI版本号 @vue/cli 4.5.19

操作步骤:

  1. app.json 中配置 enablePullDownRefresh:true
  2. 在使用的 Vue 页面添加
    onPullDownRefresh(() => {  
    console.log("onPullDownRefresh>");
    });
    
  3. 编译预览

预期结果:

  • 下拉刷新 onPullDownRefresh 能正常执行

实际结果:

  • 事件 onPullDownRefresh 未执行

bug描述:

  1. Uniapp + Vue3 编译的抖音小程序 onPullDownRefresh 不执行
  2. app.json 配置了 enablePullDownRefresh:true
  3. 导入抖音官方的代码片段(原生代码),手机上预览是执行的

更多关于uni-app + Vue3 编译的抖音小程序 onPullDownRefresh 不执行的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

github 里的找到了解决方法 https://github.com/dcloudio/uni-app/issues/745

更多关于uni-app + Vue3 编译的抖音小程序 onPullDownRefresh 不执行的实战教程也可以访问 https://www.itying.com/category-93-b0.html


在uni-app中使用Vue3开发抖音小程序时,如果遇到onPullDownRefresh不执行的问题,这通常是由于配置或实现方式不正确导致的。以下是一个确保onPullDownRefresh功能正常工作的代码示例和配置步骤。

步骤 1: 确保页面配置正确

首先,确保在pages.json中正确配置了页面路径,并且该页面允许下拉刷新。

{
  "pages": [
    {
      "path": "pages/index/index",
      "style": {
        "navigationBarTitleText": "首页",
        "enablePullDownRefresh": true // 确保这里设置为true
      }
    }
  ]
}

步骤 2: 在Vue组件中处理下拉刷新

在你的Vue组件(如pages/index/index.vue)中,添加onPullDownRefresh方法。

<template>
  <view>
    <!-- 页面内容 -->
    <text>{{ message }}</text>
  </view>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue';

const message = ref('下拉刷新试试');

// 下拉刷新处理函数
const handlePullDownRefresh = () => {
  setTimeout(() => {
    message.value = '刷新成功!';
    uni.stopPullDownRefresh(); // 停止下拉刷新动画
  }, 2000); // 模拟一个异步操作,比如从服务器获取数据
};

// 监听下拉刷新事件
onMounted(() => {
  uni.onPullDownRefresh(handlePullDownRefresh);
});

// 页面卸载时移除监听器
onUnmounted(() => {
  uni.offPullDownRefresh(handlePullDownRefresh);
});
</script>

<style scoped>
/* 样式 */
</style>

步骤 3: 测试和调试

  1. 确保你的开发环境已经正确配置,可以编译和运行抖音小程序。
  2. 运行小程序,并在首页尝试下拉刷新操作。
  3. 如果下拉刷新功能没有响应,检查以下几点:
    • pages.json中的enablePullDownRefresh是否设置为true
    • uni.onPullDownRefresh是否正确注册,并且在组件卸载时通过uni.offPullDownRefresh移除。
    • 是否有其他JavaScript错误阻止了代码执行。

通过上述步骤,你应该能够解决onPullDownRefresh不执行的问题。如果问题仍然存在,建议检查uni-app和抖音小程序的官方文档,看是否有最新的API变更或已知问题。

回到顶部