Offset 偏移量尺寸计算
介绍
获取实时的多个尺寸渲染时的实际尺寸大小,便于组件响应式偏移量的计算。
基础用法
通过 size 设置单/多个尺寸,@resize 监听元素尺寸的实时变化。
html
<vd-offset :size="sizes" @resize="handleResize" />ts
const sizes = ['10px', '5px', '8rpx', 10, '2em'];
function handleResize(size: number) {
console.log('尺寸计算变化:', size);
};TIP
size 支持所有 css 尺寸,设置 number 类型的尺寸时,会乘于 css 内预置的 1px 尺寸以支持响应式。
API
Props
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| size | 偏移大小,支持多个 | string | number | (string | number)[] | 0 |
代替原始 Props
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| custom-id | 根节点id | string | - |
| custom-class | 根节点类名 | ClassValue | - |
| custom-style | 根节点样式 | StyleValue | - |
Events
| 事件名 | 说明 | 回调参数 |
|---|---|---|
| click | 点击时触发 | MouseEvent |
| resize | 尺寸变化时触发 | number |
