mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Badge): fix badge offset of different position (#11400)
* fix(Badge): fix badge offset of different position * perf: improve code
This commit is contained in:
parent
e39f0c67d1
commit
78847b8375
@ -71,6 +71,9 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getOffsetWithMinusString = (val: string) =>
|
||||||
|
val.startsWith('-') ? val.replace('-', '') : `-${val}`;
|
||||||
|
|
||||||
const style = computed(() => {
|
const style = computed(() => {
|
||||||
const style: CSSProperties = {
|
const style: CSSProperties = {
|
||||||
background: props.color,
|
background: props.color,
|
||||||
@ -78,13 +81,23 @@ export default defineComponent({
|
|||||||
|
|
||||||
if (props.offset) {
|
if (props.offset) {
|
||||||
const [x, y] = props.offset;
|
const [x, y] = props.offset;
|
||||||
|
const { position } = props;
|
||||||
|
const offsetY = position.indexOf('top') > -1 ? 'top' : 'bottom';
|
||||||
|
const offsetX = position.indexOf('left') > -1 ? 'left' : 'right';
|
||||||
|
|
||||||
if (slots.default) {
|
if (slots.default) {
|
||||||
style.top = addUnit(y);
|
if (typeof y === 'number') {
|
||||||
|
style[offsetY] = addUnit(offsetY === 'top' ? y : -y);
|
||||||
|
} else {
|
||||||
|
style[offsetY] =
|
||||||
|
offsetY === 'top' ? addUnit(y) : getOffsetWithMinusString(y);
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof x === 'number') {
|
if (typeof x === 'number') {
|
||||||
style.right = addUnit(-x);
|
style[offsetX] = addUnit(offsetX === 'left' ? x : -x);
|
||||||
} else {
|
} else {
|
||||||
style.right = x.startsWith('-') ? x.replace('-', '') : `-${x}`;
|
style[offsetX] =
|
||||||
|
offsetX === 'left' ? addUnit(x) : getOffsetWithMinusString(x);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
style.marginTop = addUnit(y);
|
style.marginTop = addUnit(y);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user