微信小程序 端获取页面标题
getWxCurretPageTitle(route) {
let title = '';
try {
if (__wxConfig) {
let wxConfig = __wxConfig;
let page_list = __wxConfig.page || {};
let currentPageConfig = page_list[route] || page_list[route + '.html'];
let globalConfigTitle = {},
pageConfigTitle = {};
if (wxConfig.global && wxConfig.global.window && wxConfig.global.window.navigationBarTitleText) {
globalConfigTitle.titleVal = wxConfig.global.window.navigationBarTitleText;
}
if (currentPageConfig && currentPageConfig.window && currentPageConfig.window.navigationBarTitleText) {
pageConfigTitle.titleVal = currentPageConfig.window.navigationBarTitleText;
}
if (!pageConfigTitle.titleVal && __wxAppCode__) {
let page_config = __wxAppCode__[route + '.json'];
if (page_config && page_config['navigationBarTitleText']) {
pageConfigTitle.titleVal = page_config['navigationBarTitleText'];
}
}
if (title.length === 0) {
var finalTitle = this.extendObj(globalConfigTitle, pageConfigTitle);
title = finalTitle.titleVal || '';
}
}
} catch (err) {
console.error(err);
}
return title;
},
APP 端获取页面标题
getAPPCurretPageTitle(route) {
if (__uniRoutes) {
const curPageJson = __uniRoutes.find(el=>el.path === `/${route}`)
if (curPageJson) {
return curPageJson.window.navigationBarTitleText
}
return ''
}
return ''
}
条件编译获取
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
// #ifdef APP
return this.getAPPCurretPageTitle(currentPage.route)
// #endif
// #ifdef MP
return this.getWxCurretPageTitle(currentPage.route);
// #endif
3 个回复
糖丶宝可梦
// 微信小程序获取当前页面配置
靐齉齾麤龖龗 - 解决不了问题,那就解决提出问题的人
糖丶宝可梦
微信小程序 端获取页面标题
APP 端获取页面标题
条件编译获取