lc-vue-auto-height-wrapper
lc-vue-auto-height-wrapper
ResizeObserver封装, 能够方便的在template中获取父容器的尺寸
常用场景:
- 配合 element-plus 中的 table 组件实现动态容器固定表头
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
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 | ||
| 1.1.7 | ^3.2.47 | ||
| 1.1.6 | ^3.2.47 | ||
| 1.1.5 | ^3.2.47 | ||
| 1.1.4 | ^3.2.47 | ||
| 1.1.3 | ^3.2.47 | ||
| 1.1.2 | ^3.2.47 | ||
| 1.1.1 | ^3.2.47 | ||
| 1.1.0 | ^3.2.47 | ||
| 1.0.3 | ^3.2.45 | ||
| 1.0.2 | ^3.2.45 | ||
| 1.0.1 | ^3.2.45 |