React+Taro 微信小程序做一个页面,背景图需贴手机屏幕最上边覆盖展示

话不多说 直接上图

第一步

bash 复制代码
import { getSystemInfoSync } from '@tarojs/taro';

第二步

bash 复制代码
render() {
    const cardBanner = getImageUrlByGlobal('member-merge-bg.png');
    const { safeArea, statusBarHeight } = getSystemInfoSync();
    const NAV_BAR_HEIGHT = 44;
    const navBarHeight = NAV_BAR_HEIGHT + (statusBarHeight || safeArea.top);
    const containerStyle = {
      paddingTop: navBarHeight,
      backgroundImage: `url(${cardBanner})`
    };
    return <View className={prefix} style={containerStyle}></View>;
  }

第三步样式

bash 复制代码
.member-merge{
  display: flex;
  flex: 1;
  flex-direction: column;
  background-color: #f5f5f5;
  background-size: 100% auto;
  background-position: top left;
  background-repeat: no-repeat;
}
相关推荐
光影少年20 小时前
react navite 跨端核心原理
前端·react native·react.js
用户298698530141 天前
在 React 中使用 JavaScript 合并 Excel 文件
前端·javascript·react.js
CaffeinePro2 天前
告别知识点零散!React零基础通关,从环境搭建到Ant Design页面实战
前端·react.js
tcdos2 天前
不止扫码 — 微信生态深度融合(登录 + 支付 + 消息)
后端·微信小程序
小徐_23333 天前
Wot UI 2.2.0 发布:Button 新增 subtle,VideoPreview 预览体验继续增强
前端·微信小程序·uni-app
Ruihong3 天前
Vue withDefaults 转 React:VuReact 怎么处理?
vue.js·react.js·面试
用户298698530143 天前
在 React 中使用 JavaScript 将 Excel 转换为 SVG
前端·javascript·react.js
小林攻城狮4 天前
使用 Transport 节流解决 Vercel AI SDK 流式渲染卡死问题
前端·react.js