Skip to content

Commit

Permalink
fix(style): always set new styles
Browse files Browse the repository at this point in the history
close #12901
close #12946
  • Loading branch information
yyx990803 committed Dec 6, 2023
1 parent d6468c4 commit f5ef882
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/platforms/web/runtime/modules/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ function updateStyle(oldVnode: VNodeWithData, vnode: VNodeWithData) {
}
for (name in newStyle) {
cur = newStyle[name]
if (cur !== oldStyle[name]) {
// ie9 setting to null has no effect, must use empty string
setProp(el, name, cur == null ? '' : cur)
}
// ie9 setting to null has no effect, must use empty string
setProp(el, name, cur == null ? '' : cur)
}
}

Expand Down
15 changes: 15 additions & 0 deletions test/unit/modules/vdom/modules/style.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,19 @@ describe('vdom style module', () => {
expect(elm.style.fontSize).toBe('')
expect(elm.style.display).toBe('block')
})

it('border related style should update correctly', () => {
const vnode1 = new VNode('p', {
style: { border: '10px solid red', 'border-bottom': '10px solid blue' }
})
const vnode2 = new VNode('p', {
style: {
'border-right': '10px solid red',
'border-bottom': '10px solid blue'
}
})
patch(null, vnode1)
const elm = patch(vnode1, vnode2)
expect(elm.style.borderBottom).toBe('10px solid blue')
})
})

1 comment on commit f5ef882

@chenyulun
Copy link

@chenyulun chenyulun commented on f5ef882 Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<template>
  <div ref="test" :style="style111" @click="changeText">
    {{ testText }}
  </div>
</template>
<script>
export default {
  data() {
    return {
      testText: 111,
      style111: { 'border': '10px solid red', 'border-bottom': '10px solid blue' }
    }
  },
  methods: {
    changeText() {
      if (this.$refs?.test) {
        this.$refs.test.setAttribute('style', 'color:red')
      }
      // this.$forceUpdate()
      this.testText = Math.random() + ''
    }
  }
}
</script>

尤大2.6.10版本style不更新的时候可以通过setAttribute重写样式,可以变成红色,
但是您这个修改会导致我们之前的代码失效(虽然可能不是最佳的写法),一直都是蓝色
不能为了修复一部分人的问题引入破坏性改动吧

Please sign in to comment.