uniappx-youhujun快速上手
2026年7月26日小于 1 分钟
公共配置
都位于common目录下:
- 公共类型
common/type/index.uts公共类型 - 公共样式
common/common.css
已经在App.uvue中引入
<style>
/*每个页面公共css */
@import "./common/uni.css";
@import "./common/common.css";
/* #ifdef WEB */
.uni-top-window uni-tabbar .uni-tabbar {
background-color: #fff !important;
}
/* #endif */
/* #ifdef MP-WEIXIN */
page {
background-color: #efeff4;
}
/* #endif */
</style>系统配置
都位于 config目录下:
- 接口请求配置
config/setting.uts - 静态读片位置
config/image-setting.uts - 页面路径定义
config/page-setting.uts - 网络图片定义
config/picture-settting.uts
工具
所有的工具和助手都位于 utils目录下
导航拦截器
utils/interceptor
- 检测是否登录
utils/interceptor/checkAuth.uts - 检查是否绑定手机
utils/interceptor/checkPhone.uts - 检查是否绑定微信
utils/interceptor/checkWechat.uts
使用示例:
<script setup>
import {loginNavigateToInterceptor,loginSwitchTabInterceptor} from '@/utils/interceptor/checkAuth.uts'
import {phoneBindNavigateToInterceptor, phoneBindSwitchTabInterceptor} from '@/utils/interceptor/checkPhone.uts'
import {wechatBindNavigateToInterceptor, wechatBindSwitchTabInterceptor} from '@/utils/interceptor/checkWechat.uts'
onPageShow(()=>{
//登录
uni.addInterceptor('switchTab', loginSwitchTabInterceptor)
uni.addInterceptor('navigateTo', loginNavigateToInterceptor)
//手机
uni.addInterceptor('switchTab', phoneBindSwitchTabInterceptor)
uni.addInterceptor('navigateTo', phoneBindNavigateToInterceptor)
//微信
uni.addInterceptor('switchTab', wechatBindSwitchTabInterceptor)
uni.addInterceptor('navigateTo', wechatBindNavigateToInterceptor)
})
onUnload(() => {
//登录
uni.removeInterceptor('navigateTo');
uni.removeInterceptor('switchTab');
//手机
uni.removeInterceptor('navigateTo');
uni.removeInterceptor('switchTab');
//微信
uni.removeInterceptor('navigateTo');
uni.removeInterceptor('switchTab');
});
</script>