From e0335973c91af1530949ab198aa9113499ec51ec Mon Sep 17 00:00:00 2001 From: rex Date: Tue, 8 Dec 2020 15:25:15 +0800 Subject: [PATCH] fix(nav-bar): prevent getRect (#3822) fix #3818 --- packages/nav-bar/index.ts | 4 +++- packages/nav-bar/index.wxs | 16 ++++++---------- packages/wxs/style.wxs | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/nav-bar/index.ts b/packages/nav-bar/index.ts index a2d4a8fc..fd34d1a7 100644 --- a/packages/nav-bar/index.ts +++ b/packages/nav-bar/index.ts @@ -65,7 +65,9 @@ VantComponent({ wx.nextTick(() => { getRect.call(this, '.van-nav-bar').then((res) => { - this.setData({ height: res.height }); + if (res && 'height' in res) { + this.setData({ height: res.height }); + } }); }); }, diff --git a/packages/nav-bar/index.wxs b/packages/nav-bar/index.wxs index 64828328..55b4158d 100644 --- a/packages/nav-bar/index.wxs +++ b/packages/nav-bar/index.wxs @@ -1,15 +1,11 @@ /* eslint-disable */ -function barStyle(data) { - var styles = [ - ['z-index', data.zIndex], - ['padding-top', data.safeAreaInsetTop ? data.statusBarHeight + 'px' : 0], - ]; +var style = require('../wxs/style.wxs'); - return styles - .map(function (item) { - return item.join(':'); - }) - .join(';'); +function barStyle(data) { + return style({ + 'z-index': data.zIndex, + 'padding-top': data.safeAreaInsetTop ? data.statusBarHeight + 'px' : 0, + }); } module.exports = { diff --git a/packages/wxs/style.wxs b/packages/wxs/style.wxs index aa565acc..0c3d0180 100644 --- a/packages/wxs/style.wxs +++ b/packages/wxs/style.wxs @@ -4,7 +4,7 @@ var object = require('./object.wxs'); function style(styles) { return object.keys(styles) .filter(function (key) { - return styles[key]; + return styles[key] != null; }) .map(function (key) { return [key, [styles[key]]].join(':');