Encapsulation code and call refer to this article:
uniapp encapsulates public methods ( no need to refer to each page, call directly) 3001.5501
Common methods:
custom return page
(Using uni.navigateBack directly may report an error: When the page level is 1, it cannot return, so define it yourself)
//自定义返回页面
goBack: function() {
var pages = getCurrentPages();
if (pages.length > 1) {
uni.navigateBack({
delta: 1, //返回层数,2则上上页
})
} else {
uni.switchTab({
url: '/pages/home/index'
})
}
},
preview picture
(The value can be passed (image array, index) or single image src)
//预览图片
previewPic: function(picArray, index) {
if (index == undefined) {
let array = [];
array.push(picItem);
uni.previewImage({
urls: array,
current: array[0]
});
} else {
uni.previewImage({
urls: picArray,
current: index
});
}
},