2***@qq.com
2***@qq.com
  • 发布:2025-03-06 18:44
  • 更新:2025-03-10 12:10
  • 阅读:202

movable-view重新定义xy初始化

分类:uni-app

产品分类: uniapp/H5

PC开发环境操作系统: Windows

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

HBuilderX类型: 正式

HBuilderX版本号: 4.45

浏览器平台: Edge

浏览器版本: 133.0.3065.92

项目创建方式: HBuilderX

App下载地址或H5⽹址: https://a.shiqin.cc/

操作步骤:

当我在movable-view缩小到最小的时候,重新定义其x坐标以及y坐标会导致视图缩放比例重新到初始化状态

预期结果:

视图缩放比例不更新,跳到定位的坐标位置

实际结果:

视图缩放比例更新,未跳到指定位置

bug描述:

当我在movable-view缩小到最小的时候,重新定义其x坐标以及y坐标会导致视图缩放比例重新到初始化状态

2025-03-06 18:44 负责人:无 分享
已邀请:
DCloud_UNI_OttoJi

DCloud_UNI_OttoJi - 日常回复 uni-app/x 问题,如果艾特我没看到,请主动私信

提供复现工程吧,并简单对比 web/微信小程序的差异,也说明你的 vue 和 HBuilderX 依赖版本

我使用 vue3+HBuilderX4.54 运行下面代码到 web ,依次点击缩小和重置,运行结果复合预期。后续提问请给予我的 demo 进行修改,描述你的修改步骤。提供更多信息,有助于定位和解答你的问题。

<template>  
    <view class="page-body">  
        <view class="uni-padding-wrap uni-common-mt">  
            <view class="uni-title uni-common-mt">  
                示例 7  
                <text>\n可放缩</text>  
            </view>  
            <movable-area scale-area>  
                <movable-view :x="x" :y="y" direction="all" @scale="onScale"  
         @change='onChange'  
         scale scale-min="0.5" scale-max="4" :scale-value="scale">text</movable-view>  
            </movable-area>  
            <view @tap="tap2" class="uni-link uni-center uni-common-mt" style="padding-bottom:80rpx;">  
                点击这里放大3倍  
            </view>  
      <button @tap="tap05">缩小到最小0.5</button>  
      <button @tap="move">重置100,100</button>  
        </view>  
    </view>  
</template>  

<script>  
    export default {  
        data() {  
            return {  
                x: 0,  
                y: 0,  
                scale: 2,  
                old: {  
                    x: 0,  
                    y: 0,  
                    scale: 2  
                }  
            }  
        },  
        methods: {  
      move(e){  
        this.x = this.old.x  
        this.y = this.old.y  
        this.$nextTick(function() {  
            this.x = 100  
            this.y = 100  
          })  
      },  
            tap: function(e) {  
                // 解决view层不同步的问题  
                this.x = this.old.x  
                this.y = this.old.y  
                this.$nextTick(function() {  
                    this.x = 30  
                    this.y = 30  
                })  
            },  
      tap05(){  
        // 解决view层不同步的问题  
        this.scale = this.old.scale  
        this.$nextTick(function() {  
            this.scale = 0.5  
        })  
      },  
            tap2() {  
                // 解决view层不同步的问题  
                this.scale = this.old.scale  
                this.scale = this.old.scale  
                this.$nextTick(function() {  
                    this.scale = 3  
                })  
            },  
            onChange: function(e) {  
        console.log('changed');  
                this.old.x = e.detail.x  
                this.old.y = e.detail.y  
            },  
            onScale: function(e) {  
        // console.log(4,e)  
        // e.detail.scale changed  

        const _scale  = e.detail.scale  
        if(_scale===0.5){  
          console.log('缩放到最小了');  
        }  
                this.old.scale = e.detail.scale  
            }  
        }  
    }  
</script>  

<style>  
    movable-view {  
        display: flex;  
        align-items: center;  
        justify-content: center;  
        height: 150rpx;  
        width: 150rpx;  
        background-color: #007AFF;  
        color: #fff;  
    }  

    movable-area {  
        height: 300rpx;  
        width: 100%;  
        background-color: #D8D8D8;  
        overflow: hidden;  
    }  

    .max {  
        width:500rpx;  
        height: 500rpx;  
    }  
</style>  
2***@qq.com

2***@qq.com (作者)

hbuildx版本为4.45 vue版本为3 小程序上没有问题web上面有我说明的问题

  • DCloud_UNI_OttoJi

    看我更新,我提供了复现工程,基于我的修改说明你的问题

    2025-03-10 12:10

要回复问题请先登录注册