Component({ properties: { radius: { type: Number }, //半径 单位px useSlot: { type: Boolean }, zIndex: { type: Number, value: 99 } }, data: { top: "550px", left: "345px", viewHeight: null, alternative: false, viewWidth: 375 }, lifetimes: { attached: function () { this.setData({ userid: wx.getStorageSync('userMsg').userid }) let that = this; wx.getSystemInfo({ success: (res => that.setData({ viewHeight: res.windowHeight, viewWidth: res.windowWidth // ✅ 加这一行 })) }); }, }, methods: { viewTouchMove(e) { let left = e.touches[0].pageX; if (left > (this.data.viewWidth - this.data.radius)) left = this.data.viewWidth - (this.data.radius / 2); if (left < 0 + this.data.radius) left = 0 + this.data.radius; let top = e.touches[0].pageY; if (top < 0 + this.data.radius) top = 0 + this.data.radius; if (top > this.data.viewHeight - this.data.radius) top = this.data.viewHeight - this.data.radius; this.setData({ left: left + 'px', top: top + 'px' }) }, imageOnErr(e) { console.log("图片加载失败") this.setData({ alternative: true }) } } })