fix(global-style): shouldn't apply style transition on first mount

This commit is contained in:
07akioni 2021-09-21 23:50:00 +08:00
parent 1843ee4dc5
commit 2687703bcc
3 changed files with 24 additions and 3 deletions

View File

@ -1,5 +1,11 @@
# CHANGELOG
## Pending
### Fixes
- Fix `n-global-style` applies style transition on first mount.
## 2.19.1 (2021-09-21)
### Fixes

View File

@ -1,5 +1,11 @@
# CHANGELOG
## Pending
### Fixes
- 修复 `n-global-style` 在首次挂载时应用样式过渡
## 2.19.1 (2021-09-21)
### Fixes

View File

@ -17,6 +17,7 @@ export default defineComponent({
const { body } = document
const { style } = body
let styleApplied = false
let firstApply = true
onBeforeMount(() => {
watchEffect(() => {
const {
@ -34,14 +35,22 @@ export default defineComponent({
)
: commonLight
if (styleApplied || !body.hasAttribute('n-styled')) {
body.setAttribute('n-styled', '')
styleApplied = true
style.backgroundColor = bodyColor
style.color = textColor2
style.fontSize = fontSize
style.fontFamily = fontFamily
style.lineHeight = lineHeight
style.transition = `color .3s ${cubicBezierEaseInOut}, background-color .3s ${cubicBezierEaseInOut}`
const transition = `color .3s ${cubicBezierEaseInOut}, background-color .3s ${cubicBezierEaseInOut}`
if (firstApply) {
setTimeout(() => {
style.transition = transition
}, 0)
} else {
style.transition = transition
}
body.setAttribute('n-styled', '')
styleApplied = true
firstApply = false
} else if (__DEV__) {
warn(
'global-style',