从用户研究出发,先明确个性化目标(如提升留存、转化、使用时长),再按“界面—功能—数据—消息”四层推进,配合模块化架构与数据驱动持续优化。核心流程:
// app.js
App({
onLaunch() {
const theme = wx.getStorageSync('userTheme') || 'light';
this.globalData.theme = theme;
this.updateThemeStyle(theme);
},
globalData: { theme: 'light' },
updateThemeStyle(theme) {
const isDark = theme === 'dark';
wx.setNavigationBarColor({
frontColor: isDark ? '#ffffff' : '#000000',
backgroundColor: isDark ? '#000000' : '#ffffff'
});
}
});
// theme.js
function changeTheme(newTheme) {
const app = getApp();
app.globalData.theme = newTheme;
wx.setStorageSync('userTheme', newTheme);
app.updateThemeStyle(newTheme);
}
module.exports = { changeTheme };
<!-- page/index/index.wxml -->
<view class="page" data-theme="{{theme}}">
<text>当前主题:{{theme}}</text>
<button bindtap="switchTheme">切换主题</button>
</view>
/* app.wxss */
:root {
--bg: #ffffff;
--text: #000000;
}
[data-theme="dark"] {
--bg: #000000;
--text: #ffffff;
}
.page { background: var(--bg); color: var(--text); padding: 20rpx; }
// page/index/index.js
const theme = require('../../theme.js');
Page({
data: { theme: 'light' },
onLoad() {
this.setData({ theme: getApp().globalData.theme });
},
switchTheme() {
const next = this.data.theme === 'light' ? 'dark' : 'light';
theme.changeTheme(next);
this.setData({ theme: next });
}
});
上述示例展示了在App.js启动时读取本地主题、在theme.js中切换并持久化、以及通过CSS 变量应用到页面样式的完整链路,可作为轻量级个性化的起点。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。