lc-vue-auto-height-wrapper

ResizeObserver封装
1,165
Install
npm install lc-vue-auto-height-wrapper
Latest Version:1.1.14
Vue:3
License:MIT
Last Updated:May 5, 2023
Links: GitHub  ·  npm
Maintainer: lvliqi

lc-vue-auto-height-wrapper

ResizeObserver封装, 能够方便的在template中获取父容器的尺寸

常用场景:

  • 配合 element-plus 中的 table 组件实现动态容器固定表头

Demo

demo

安装

npm i lc-vue-auto-height-wrapper 

例子

<script setup lang="ts">
  import { ref, computed } from 'vue';
  import { AutoHeightWrapper } from 'lc-vue-auto-height-wrapper';
  const width = ref(100);
  const height = ref(100);
  const style = computed(()=>({
    width: `${width.value}px`,
    height: `${height.value}px`
  }))
</script>

<template>
  <el-slider v-model="width" :min='100' :max='500' />
  <el-slider v-model="height" :min='100' :max='500' />
  <div style='border: 1px solid #000; display: inline-block'>
    <div :style='style'>
      <AutoHeightWrapper>
        <template #default="{size}">
          {{size}}
        </template>
      </AutoHeightWrapper>  
    </div>
  </div>
</template>

API

Slots

插槽名 说明 参数
default 自定义内容 size: { width: number, height: number }

Related Packages

vue-resize-observer

Vue普通元素resize事件监听

148,954 63
v-resize-observer

Resize observer for Vue. Detect size changes of DOM elements. Support Vue's dire...

31,577 4
@juggle/resize-observer

Polyfills the ResizeObserver API and supports box size options from the latest s...

274,867,962 988
@anilanar/resize-observer

Polyfills the ResizeObserver API and supports box size options from the latest s...

18,217 987
vue-use-scroll-size-observer

Vue3 composable that provides a simple and efficient way to observe changes to e...

855 0

Version History

Version Released Vue License
1.1.14 ^3.2.47 MIT
1.1.13 ^3.2.47 MIT
1.1.11 ^3.2.47 MIT
1.1.9 ^3.2.47 MIT
1.1.8 ^3.2.47