From 9f15fe9fdf5492d058419d48769516839b4a79a5 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Thu, 12 Aug 2021 15:42:33 +0800 Subject: [PATCH] fix: add resize-observer-polyfill #4508 close #4508 --- components/vc-align/util.ts | 1 + components/vc-resize-observer/index.tsx | 7 +++---- components/vc-slick/src/inner-slider.js | 1 + components/vc-tabs/src/ScrollableTabBarNode.jsx | 1 + package.json | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/components/vc-align/util.ts b/components/vc-align/util.ts index ecff1cdfc..585828c1b 100644 --- a/components/vc-align/util.ts +++ b/components/vc-align/util.ts @@ -1,5 +1,6 @@ import contains from '../vc-util/Dom/contains'; import type { TargetPoint } from './interface'; +import ResizeObserver from 'resize-observer-polyfill'; export function isSamePoint(prev: TargetPoint, next: TargetPoint) { if (prev === next) return true; diff --git a/components/vc-resize-observer/index.tsx b/components/vc-resize-observer/index.tsx index 850f27e6b..86613fc4a 100644 --- a/components/vc-resize-observer/index.tsx +++ b/components/vc-resize-observer/index.tsx @@ -1,5 +1,6 @@ // based on rc-resize-observer 1.0.0 import type { PropType } from 'vue'; +import ResizeObserver from 'resize-observer-polyfill'; import { defineComponent, getCurrentInstance, @@ -18,7 +19,7 @@ interface ResizeObserverState { offsetWidth: number; } -const ResizeObserver = defineComponent({ +export default defineComponent({ name: 'ResizeObserver', props: { disabled: Boolean, @@ -110,7 +111,7 @@ const ResizeObserver = defineComponent({ } if (!resizeObserver && element) { - resizeObserver = new window.ResizeObserver(onResize); + resizeObserver = new ResizeObserver(onResize); resizeObserver.observe(element); } }; @@ -135,5 +136,3 @@ const ResizeObserver = defineComponent({ }; }, }); - -export default ResizeObserver; diff --git a/components/vc-slick/src/inner-slider.js b/components/vc-slick/src/inner-slider.js index 421ef43d9..828e79bad 100644 --- a/components/vc-slick/src/inner-slider.js +++ b/components/vc-slick/src/inner-slider.js @@ -1,4 +1,5 @@ import debounce from 'lodash-es/debounce'; +import ResizeObserver from 'resize-observer-polyfill'; import classnames from '../../_util/classNames'; import BaseMixin from '../../_util/BaseMixin'; import defaultProps from './default-props'; diff --git a/components/vc-tabs/src/ScrollableTabBarNode.jsx b/components/vc-tabs/src/ScrollableTabBarNode.jsx index 806bc9a32..2e1650e47 100644 --- a/components/vc-tabs/src/ScrollableTabBarNode.jsx +++ b/components/vc-tabs/src/ScrollableTabBarNode.jsx @@ -1,4 +1,5 @@ import debounce from 'lodash-es/debounce'; +import ResizeObserver from 'resize-observer-polyfill'; import PropTypes from '../../_util/vue-types'; import BaseMixin from '../../_util/BaseMixin'; import { getComponent, getSlot } from '../../_util/props-util'; diff --git a/package.json b/package.json index f339f3115..d67796e3b 100644 --- a/package.json +++ b/package.json @@ -160,7 +160,6 @@ "querystring": "^0.2.0", "raw-loader": "^4.0.2", "reqwest": "^2.0.5", - "resize-observer-polyfill": "^1.5.1", "rimraf": "^3.0.0", "rucksack-css": "^1.0.2", "selenium-server": "^3.0.1", @@ -214,6 +213,7 @@ "lodash-es": "^4.17.15", "moment": "^2.27.0", "omit.js": "^2.0.0", + "resize-observer-polyfill": "^1.5.1", "scroll-into-view-if-needed": "^2.2.25", "shallow-equal": "^1.0.0", "vue-types": "^3.0.0",