关于uniapp 中uview input组件设置为readonly 或者disabled input区域不可点击问题

<u-form-item
              v-for="item in formLabel"
                :key="item.prop"
                :label="item.label"
                :labelWidth="item.labelWidth ? item.labelWidth : '140rpx'"
                :prop="item.prop"
                :borderBottom="item.borderBottom"
                ref="item1"
                @click="bindClick(item)"
          >
                <u--input
                    v-model="formData[item.prop]"
                    :placeholder="item.placeholder ? item.placeholder : '请输入' "
                    border="none"
                    class="custom-input"
                    :readonly="item.type == 'select'"
                    :suffixIcon="item.icon"
                    style="pointer-events:none"
                ></u--input>
            </u-form-item>

在最外层绑定@click="bindClick(item)" 事件 在u--input 设置style="pointer-events:none"

就可以顺利触发bindClick 事件

在使用uniappuview组件时,如果在支付宝小程序中遇到ref引用为undefined的问题,可以尝试以下几种解决方法: 1. **确保ref正确设置**: 确保在组件中正确设置了ref属性。例如: ```html <u-button ref="myButton">点击我</u-button> ``` 2. **使用$nextTick**: 在某些情况下,组件可能还没有完全渲染,导致ref引用为undefined。可以使用$nextTick来确保组件已经渲染完成: ```javascript this.$nextTick(() => { console.log(this.$refs.myButton); }); ``` 3. **检查组件层级**: 确保ref引用的组件在当前组件的层级结构中是正确的。例如,如果ref在子组件中引用父组件的某个元素,可能需要调整层级结构。 4. **检查组件名称**: 确保ref名称和引用名称一致。例如,如果ref名称是myButton,那么在JavaScript中引用时也应该是this.$refs.myButton。 5. **调试和日志**: 在JavaScript中添加日志,检查ref引用是否正确。例如: ```javascript console.log(this.$refs); ``` 6. **确保组件已加载**: 确保组件已经加载完成。例如,在页面生命周期钩子中使用ref引用时,确保在mounted或onReady钩子中使用。 7. **检查uview版本**: 确保使用的uview版本与uniapp版本兼容。可以尝试更新uview到最新版本。 示例代码: ```html <template> <view> <u-button ref="myButton">点击我</u-button> </view> </template> <script> export default { mounted() { this.$nextTick(() => { console.log(this.$refs.myButton); }); }, methods: { handleClick() { if (this.$refs.myButton) { this.$refs.myButton.click(); } else { console.log('ref引用为undefined'); } } } } </script> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值