index.nvue
<template>
<view class="content">
<button type="primary" class="btn" @click="jumpTest">test页面</button>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello'
};
},
onLoad() {},
methods: {
jumpTest() {
uni.navigateTo({
url: '../test/test'
});
}
}
};
</script>
<style>
.btn {
width: 690rpx;
margin: 15px;
}
</style>
text.nvue
<template>
<view>
<text>{{ count }}</text>
<button type="primary" class="btn" @click="showKey">显示软键盘</button>
<button type="warn" class="btn" @click="hideKey">隐藏软键盘</button>
</view>
</template>
<script>
export default {
data() {
return {
count: 1,
timer: null
};
},
onShow() {
uni.onKeyboardHeightChange(res => {
console.log(res);
if (res.height == 0) {
if (this.timer) {
try {
clearInterval(this.timer);
} catch (err) {
console.log(err);
}
}
}
});
},
onHide() {
uni.offKeyboardHeightChange(() => {});
// if (this.timer) {
// clearInterval(this.timer);
// }
},
methods: {
showKey() {
// #ifdef APP-NVUE
plus.key.showSoftKeybord();
// #endif
console.log(this.timer);
if (this.timer) {
clearInterval(this.timer);
}
this.timer = setInterval(() => {
this.count = Math.random() * 30;
}, 1500);
},
hideKey() {
// #ifdef APP-NVUE
plus.key.hideSoftKeybord();
// #endif
if (this.timer) {
clearInterval(this.timer);
}
}
}
};
</script>
<style scoped>
.btn {
width: 690rpx;
margin: 30rpx;
}
</style>
3***@qq.com (作者)
能举个例子吗
2022-09-19 11:19
DCloud_UNI_Anne
回复 3***@qq.com: 参考文档:https://uniapp.dcloud.net.cn/api/key.html#onkeyboardheightchange
2022-09-19 17:40
3***@qq.com (作者)
回复 DCloud_UNI_Anne: 好的,谢谢
2022-09-19 18:18
3***@qq.com
那可以设置监听到methods里面的方法,但在取消的时候它又不行了是什么原因?
2023-12-07 14:16