8000 handle v-pre on component root node (fix #2026) · Hsinwe/vue@bbf5e59 · GitHub
[go: up one dir, main page]

Skip to content

Commit bbf5e59

Browse files
committed
handle v-pre on component root node (fix vuejs#2026)
1 parent 81d38aa commit bbf5e59

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/instance/internal/lifecycle.js

Lines changed: 6 additions & 1 deletion
10B6A
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { replace } from '../../util/index'
1+
import { replace, getAttr } from '../../util/index'
22
import Directive from '../../directive'
33
import { compile, compileRoot, transclude } from '../../compiler/index'
44

@@ -49,6 +49,11 @@ export default function (Vue) {
4949
el = transclude(el, options)
5050
this._initElement(el)
5151

52+
// handle v-pre on root node (#2026)
53+
if (el.nodeType === 1 && getAttr(el, 'v-pre') !== null) {
54+
return
55+
}
56+
5257
// root is always compiled per-instance, because
5358
// container attrs and props can be different every time.
5459
var contextOptions = this._context && this._context.$options

test/unit/specs/directives/public/pre_spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ var Vue = require('../../../../../src/index')
22

33
describe('v-pre', function () {
44

5+
beforeEach(function () {
6+
spyWarns()
7+
})
8+
59
it('should work', function () {
610
var vm = new Vue({
711
el: document.createElement('div'),
@@ -12,4 +16,17 @@ describe('v-pre', function () {
1216
})
1317
expect(vm.$el.firstChild.textContent).toBe('{{a}}')
1418
})
19+
20+
it('should work on root node', function () {
21+
var vm = new Vue({
22+
el: document.createElement('div'),
23+
template: '<div v-pre>{{a}}</div>',
24+
replace: true,
25+
data: {
26+
a: 123
27+
}
28+
})
29+
expect(vm.$el.textContent).toBe('{{a}}')
30+
expect(getWarnCount()).toBe(0)
31+
})
1532
})

0 commit comments

Comments
 (0)
0