在 uni-app 中,可以通过配置 `softinputMode` 控制键盘行为。默认可能是 `adjustResize`(撑开页面),可改为覆盖模式。
配置方法
方法一:在 `pages.json` 中为特定页面配置
在需要键盘覆盖的页面的 `style` 中添加 `softinputMode`:
```json:src/pages.json
{
"pages": [
{
"path": "pages/review/index",
"style": {
"navigationBarTitleText": "审校",
"navigationStyle": "custom",
"softinputMode": "adjustNothing"
}
}
// ... 其他页面
]
}
```
方法二:在 `manifest.json` 中配置全局默认值
在 `app-plus` 中添加全局配置:
```json:src/manifest.json
{
"app-plus": {
"usingComponents": true,
"nvueStyleCompiler": "uni-app",
"compilerVersion": 3,
"softinputMode": "adjustNothing",
// ... 其他配置
}
}
```
键盘模式说明
-
`adjustResize`:键盘撑开页面,页面内容被压缩(默认可能为此)
-
`adjustPan`:键盘平移页面,不改变页面大小
-
`adjustNothing`:键盘覆盖在页面上,不影响页面布局(推荐用于覆盖模式)
建议
-
全局配置:在 `manifest.json` 的 `app-plus` 中设置 `"softinputMode": "adjustNothing"`,让所有页面默认使用覆盖模式。
-
页面级配置:如果只有部分页面需要,在 `pages.json` 中为对应页面单独配置。