Skip to content

Commit 6c48247

Browse files
committed
fix(v-pre): do not alter attributes
close vuejs#10087
1 parent ff911c9 commit 6c48247

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/platforms/web/runtime/modules/attrs.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) {
3939
cur = attrs[key]
4040
old = oldAttrs[key]
4141
if (old !== cur) {
42-
setAttr(elm, key, cur)
42+
setAttr(elm, key, cur, vnode.data.pre)
4343
}
4444
}
4545
// #4391: in IE9, setting type can reset value for input[type=radio]
@@ -59,9 +59,11 @@ function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) {
5959
}
6060
}
6161

62-
function setAttr (el: Element, key: string, value: any) {
62+
function setAttr (el: Element, key: string, value: any, isInPre: any) {
6363
if (el.tagName.indexOf('-') > -1) {
6464
baseSetAttr(el, key, value)
65+
} else if(isInPre) {
66+
baseSetAttr(el, key, value)
6567
} else if (isBooleanAttr(key)) {
6668
// set attribute for blank value
6769
// e.g. <option disabled>Select one</option>

test/unit/features/directives/pre.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,15 @@ describe('Directive v-pre', function () {
4242
vm.$mount()
4343
expect(vm.$el.firstChild.tagName).toBe('VTEST')
4444
})
45+
46+
// #10087
47+
it('should not compile attributes', function () {
48+
Vue.component('vtest', { template: ` <div>Hello World</div>` })
49+
const vm = new Vue({
50+
template: '<div v-pre><vtest open="hello"></vtest></div>',
51+
replace: true
52+
})
53+
vm.$mount()
54+
expect(vm.$el.firstChild.getAttribute('open')).toBe('hello')
55+
})
4556
})

0 commit comments

Comments
 (0)