向上一个页面传递值
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