Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c4b4134

Browse files
committed
feat: convert px to vw in inline styles
1 parent 80d9c65 commit c4b4134

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

‎src/components/Container.vue‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script setup lang="ts">
2+
import vw from '@/utils/inline-px-to-vw'
3+
24
defineProps({
35
paddingT: {
46
type: Number,
@@ -14,7 +16,7 @@ defineProps({
1416
<template>
1517
<main
1618
class="absolute left-0 h-full w-full overflow-y-auto"
17-
:style="`padding-top: ${paddingT}px; padding-left: ${paddingX}px; padding-right: ${paddingX}px`"
19+
:style="`padding-top: ${vw(paddingT)}; padding-left: ${vw(paddingX)}; padding-right: ${vw(paddingX)}`"
1820
>
1921
<slot />
2022
</main>

‎src/utils/inline-px-to-vw.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { round } from 'lodash-es'
2+
3+
// 设计稿的宽度
4+
const width = 375
5+
6+
/**
7+
* vw 转换
8+
* @param {number} n
9+
*/
10+
export default function vw(n: number) {
11+
if (n === 0)
12+
return n
13+
const vwN = round(n * 100 / width, 3)
14+
return `${vwN}vw`
15+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /