uni-app bindingx 绑定list 无法监听到滚动 无法实现动画

uni-app bindingx 绑定list 无法监听到滚动 无法实现动画

开发环境 版本号 项目创建方式
Windows win10 HBuilderX

产品分类:uniapp/App

PC开发环境操作系统:Windows

PC开发环境操作系统版本号:win10

HBuilderX类型:Alpha

HBuilderX版本号:3.4.8

手机系统:Android

手机系统版本号:Android 12

手机厂商:华为

手机机型:华为P40

页面类型:nvue

vue版本:vue2

打包方式:云端

项目创建方式:HBuilderX

操作步骤:

这个bindingx 非常的不稳定,明明一样的代码,有时候能绑定,能实现动画,有时候就不行,每次uniapp 更新,就大概率掉链子,之前行了的又不行了。这动画贼难做。用其他方式做,这性能卡成狗了。  
我反复纠结在 这个setTimeout这边,简直浪费时间啊 这肯定有Bug啊,而且按道理,onReady时已经完成了渲染,再加这个东西要干嘛。  
加了后就出现,一会可以,一会不可以情况。这个BUG问题,困扰了1年多了。解决不了了  

预期结果:

稳定的可以

实际结果:

不稳定,一会可以,一会不可以,绝对有BUG

更多关于uni-app bindingx 绑定list 无法监听到滚动 无法实现动画的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

你用这个@scroll=“scroll” 不就很方便

更多关于uni-app bindingx 绑定list 无法监听到滚动 无法实现动画的实战教程也可以访问 https://www.itying.com/category-93-b0.html


在使用 UniApp 和 BindingX 进行开发时,如果你遇到无法监听到列表滚动事件或无法实现动画的问题,可能是由于以下几个原因导致的。以下是一些可能的解决方案和排查步骤:

1. 确保正确绑定事件

首先,确保你正确绑定了滚动事件。在 UniApp 中,通常使用 scroll 事件来监听滚动。例如:

<scroll-view [@scroll](/user/scroll)="handleScroll">
  <!-- 列表内容 -->
</scroll-view>

handleScroll 方法中,你可以处理滚动事件并触发相应的动画。

2. 使用 BindingX 绑定滚动事件

BindingX 提供了更强大的事件绑定能力,你可以使用 expression 来绑定滚动事件。例如:

const bindingX = uni.requireNativePlugin('bindingx');

bindingX.bind({
  eventType: 'scroll',
  props: [
    {
      element: 'scrollViewId', // 替换为你的 scroll-view 的 id
      property: 'scrollY',
      expression: 'y'
    }
  ],
  anchor: 'scrollViewId', // 替换为你的 scroll-view 的 id
  callback: function(event) {
    console.log('Scroll Y:', event.y);
    // 在这里处理滚动事件并触发动画
  }
});

3. 检查元素 ID 和绑定

确保你在 bind 方法中使用的 elementanchor 是正确的元素 ID。如果 ID 不匹配,BindingX 将无法正确绑定事件。

4. 确保 BindingX 插件已正确引入

确保你已经在项目中正确引入了 BindingX 插件。你可以在 pages.json 中检查是否已经配置了 BindingX 插件:

{
  "pages": [
    // 你的页面配置
  ],
  "plugins": {
    "bindingx": {
      "version": "1.0.0",
      "provider": "your-provider"
    }
  }
}

5. 检查滚动容器类型

确保你使用的是 scroll-view 组件,而不是普通的 view 组件。scroll-view 组件是专门用于处理滚动事件的。

6. 调试和日志

callback 函数中添加日志输出,检查是否能够正确接收到滚动事件。如果 callback 函数没有被调用,可能是绑定事件失败。

7. 检查 UniApp 和 BindingX 版本

确保你使用的 UniApp 和 BindingX 版本是兼容的。有时,版本不兼容可能导致某些功能无法正常工作。

8. 使用原生组件

如果以上方法都无法解决问题,考虑使用原生组件来实现滚动和动画。UniApp 支持使用原生组件,你可以通过 uni.requireNativePlugin 引入原生组件来实现更复杂的功能。

示例代码

以下是一个完整的示例代码,展示了如何使用 BindingX 绑定滚动事件并实现动画:

<template>
  <scroll-view id="scrollViewId" [@scroll](/user/scroll)="handleScroll">
    <!-- 列表内容 -->
  </scroll-view>
</template>

<script>
export default {
  methods: {
    handleScroll(event) {
      console.log('Scroll event:', event);
    },
    bindScrollEvent() {
      const bindingX = uni.requireNativePlugin('bindingx');

      bindingX.bind({
        eventType: 'scroll',
        props: [
          {
            element: 'scrollViewId',
            property: 'scrollY',
            expression: 'y'
          }
        ],
        anchor: 'scrollViewId',
        callback: function(event) {
          console.log('Scroll Y:', event.y);
          // 在这里处理滚动事件并触发动画
        }
      });
    }
  },
  mounted() {
    this.bindScrollEvent();
  }
}
</script>
回到顶部