Guoguo-notes
主页
常用笔记
vue笔记及周边生态
  • 团队协作及规范
  • 项目框架及架构
  • 飞码篇
  • Java
  • React笔记
GitHub
主页
常用笔记
vue笔记及周边生态
  • 团队协作及规范
  • 项目框架及架构
  • 飞码篇
  • Java
  • React笔记
GitHub
  • 常用笔记

    • 1. CSS笔记.md
    • 2. Echarts.md
    • 3. Git 代码管理.md
    • 4. Html 笔记.md
    • 5. TypeScript.md
    • 6. axios 请求拦截.md
    • 7. js常规.md
    • 8. npm.md
    • 9. sh 笔记.md
    • 10. valibot校验学习.md
    • 11. 云开发教程.md
    • 12. 公共API接口.md
    • 13. 小程序笔记.md
    • 14. 插件库.md
    • 15. 服务器.md
    • 16. 服务器部署教学.md
    • 17. 浏览器px to rem适配.md
    • 18. 登录逻辑.md
    • 19. 网站配色.md
    • 20. 跨域代理.md

向上一个页面传递值

  backConfirm() {
      var pages = getCurrentPages()
      // if (pages.length > 2) {
      var currPage = pages[pages.length - 1] //当前页面
      var prevPage = pages[pages.length - 2] //上一个页面
      // #ifdef H5
      prevPage.$vm.unittitle = val //h5写法
      // #endif
  
      prevPage.setData({
        theUnittitle: {id:1}
      }) 

        uni.navigateBack()

    }

获取下个页面传递过来的值

		//兼容小程序,获取选中的值
		//#ifdef MP-WEIXIN||MP-QQ
		let pages = getCurrentPages();
		let currPage = pages[pages.length - 1];
		this.unittitle = currPage.data.theUnittitle;
		if (currPage.data.theUnittitle) {
			this.$set(this.model, 'work', currPage.data.theUnittitle.unitname)
			this.$set(this.model, 'unitid', currPage.data.theUnittitle.unitid)
			this.$set(this.model, 'topOrganizId', currPage.data.theUnittitle.topOrganizId)
			this.$set(this.model, 'topOrganizName', currPage.data.theUnittitle.topOrganizName)
		}
		// #endif

分享

<u-cell icon="share" title="分享豫直先锋" openType="share" arrow-direction="right" @click="clickHandler"
						:border="false"></u-cell>
//分享
    uni.$u.mpShare.title = '豫直先锋'
    uni.$u.mpShare.path = 'pages/index/index'
    uni.$u.mpShare.imageUrl = '这个分享图片和分享标题做成后台可以替换的'
// #endif

键盘被抬起后 输入框位置适配

const inputBoxBottom = ref(0);

const onKeyboardShow = (height: number) => {
  inputBoxBottom.value = height;
};
const onKeyboardHide = () => {
  inputBoxBottom.value = 0;
};

onMounted(async () => {
  uni.onKeyboardHeightChange((res) => {
    const height = res.height;
    if (height > 0) {
      onKeyboardShow(height);
    } else {
      onKeyboardHide();
    }
  });
}

1.定义底部输入框外层view距离底部距离的变量inputBoxBottom:

data:{
  inputBoxBottom:0
}

2.在页面的onLoad生命周期中监听键盘事件,记录键盘弹起的高度,并将高度赋值给inputBoxBottom

onLoad(options: any) {
    wx.onKeyboardHeightChange((res) => {
      const height = res.height;
      if (height > 0) {
        this.onKeyboardShow(height);
      } else {
        this.onKeyboardHide();
      }
    });
  },
onKeyboardShow(height: number) {
    this.setData({
      inputBoxBottom: height,
    });
},
onKeyboardHide() {
    // 处理键盘收起逻辑
    this.setData({
      inputBoxBottom: 0,
    });
}

3.将inputBoxBottom变量设置给底部输入框外层的view标签:

<view class="input-box" style="bottom:{{inputBoxBottom}}px"></view>

4.设置textarea标签adjust-position="false",保证键盘弹起时,页面不会被顶起,只是底部输入框bottom变化而使输入框抬起至键盘上方:

<textarea adjust-position="{{false}}" ></textarea>

链接:https://juejin.cn/post/7512502594020655155

Edit this page
Last Updated:
Contributors: 袁果锅
Prev
12. 公共API接口.md
Next
14. 插件库.md