lifetimes: { attached() { let that = this let userPhoneStr = '' let userEmailStr = '' let peopleNameStr = '' let userPhone = '' let userPhoneInvoice = wx.getStorageSync('memberMsg').memberMobile userPhone = userPhoneInvoice let arr = userPhoneInvoice.split('') for (let x = 0; x < arr.length; x++) { if ((x >= 0 && x <= 2) || (x >= 7 && x < arr.length)) { userPhoneStr += arr[x] } else { userPhoneStr += '*' } } if (wx.getStorageSync('userEmailInvoice') != '') { userEmailStr = wx.getStorageSync('userEmailInvoice') } if (wx.getStorageSync('userNameInvoice') != '') { peopleNameStr = wx.getStorageSync('userNameInvoice') } this.setData({ userPhoneStr, userEmailStr, peopleNameStr, userPhone }) wx.getSystemInfo({ success: e => { that.setData({ pageHeight: e.windowHeight, invoiceModalMaxHeight: e.windowHeight * 0.6 }) if (that.data.isiPhoneX) { that.setData({ invoiceModalScrollMaxHeight: e.windowHeight * 0.6 - 120 }) } else { that.setData({ invoiceModalScrollMaxHeight: e.windowHeight * 0.6 - 90 }) } } }) } }, 改成uniapp
时间: 2024-02-10 22:08:23 浏览: 111
可以将该段代码转换为uni-app的语法:
```
export default {
onReady() {
let that = this;
let userPhoneStr = '';
let userEmailStr = '';
let peopleNameStr = '';
let userPhone = '';
let userPhoneInvoice = uni.getStorageSync('memberMsg').memberMobile;
userPhone = userPhoneInvoice;
let arr = userPhoneInvoice.split('');
for (let x = 0; x < arr.length; x++) {
if ((x >= 0 && x <= 2) || (x >= 7 && x < arr.length)) {
userPhoneStr += arr[x];
} else {
userPhoneStr += '*';
}
}
if (uni.getStorageSync('userEmailInvoice') != '') {
userEmailStr = uni.getStorageSync('userEmailInvoice');
}
if (uni.getStorageSync('userNameInvoice') != '') {
peopleNameStr = uni.getStorageSync('userNameInvoice');
}
this.setData({
userPhoneStr,
userEmailStr,
peopleNameStr,
userPhone
});
uni.getSystemInfo({
success: e => {
that.setData({
pageHeight: e.windowHeight,
invoiceModalMaxHeight: e.windowHeight * 0.6
});
if (that.data.isiPhoneX) {
that.setData({
invoiceModalScrollMaxHeight: e.windowHeight * 0.6 - 120
});
} else {
that.setData({
invoiceModalScrollMaxHeight: e.windowHeight * 0.6 - 90
});
}
}
});
}
}
```
注意,我将`attached`改为了`onReady`,因为在uni-app中没有`attached`这个生命周期函数。另外,我使用了`uni.`代替了`wx.`,因为uni-app是跨平台框架,需要使用uni-app提供的API。
阅读全文