uni-app点击按钮显示输入框
时间: 2024-05-30 21:06:28 浏览: 182
以下是uni-app中点击按钮显示输入框的例子:
1. 在button组件上绑定点击事件,在事件处理函数中设置flag变量为true
```html
<template>
<view>
<button @tap="showInput">点击输入</button>
<input v-show="flag" type="text" placeholder="请输入内容"></input>
</view>
</template>
<script>
export default {
data() {
return {
flag: false
}
},
methods: {
showInput() {
this.flag = true;
}
}
}
</script>
```
2.在button组件上绑定点击事件,使用uni.showModal方法来弹出带有输入框的模态框
```html
<template>
<view>
<button @tap="showInput">点击输入</button>
</view>
</template>
<script>
export default {
methods: {
showInput() {
uni.showModal({
title: '请输入内容',
content: '',
confirmText: '确认',
cancelText: '取消',
showCancel: true,
success(res) {
if (res.confirm) {
console.log('输入的内容为:', res.content)
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
}
}
</script>
```
阅读全文
相关推荐


















