Преглед изворни кода

inline repeat instances should inherit assets even in strict mode (fix #1080)

Evan You пре 11 година
родитељ
комит
d281abd4f6
3 измењених фајлова са 26 додато и 4 уклоњено
  1. 3 3
      src/directives/repeat.js
  2. 4 1
      src/util/options.js
  3. 19 0
      test/unit/specs/misc_spec.js

+ 3 - 3
src/directives/repeat.js

@@ -107,7 +107,7 @@ module.exports = {
       // default constructor
       this.Ctor = _.Vue
       // inline repeats should inherit
-      this.inherit = true
+      this.inline = true
       // important: transclude with no options, just
       // to ensure block start and block end
       this.template = compiler.transclude(this.template)
@@ -370,12 +370,12 @@ module.exports = {
     var vm = parent.$addChild({
       el: templateParser.clone(this.template),
       data: data,
-      inherit: this.inherit,
+      inherit: this.inline,
       template: this.inlineTemplate,
       // repeater meta, e.g. $index, $key
       _meta: meta,
       // mark this as an inline-repeat instance
-      _repeat: this.inherit,
+      _repeat: this.inline,
       // is this a component?
       _asComponent: this.asComponent,
       // linker cachable if no inline-template

+ 4 - 1
src/util/options.js

@@ -341,7 +341,10 @@ exports.mergeOptions = function merge (parent, child, vm) {
 
 exports.resolveAsset = function resolve (options, type, id) {
   var asset = options[type][id]
-  while (!config.strict && !asset && options._parent) {
+  while (
+    !asset && options._parent &&
+    (!config.strict || options._repeat)
+  ) {
     options = options._parent.$options
     asset = options[type][id]
   }

+ 19 - 0
test/unit/specs/misc_spec.js

@@ -244,6 +244,25 @@ describe('Misc', function () {
     Vue.config.strict = false
   })
 
+  it('strict mode for repeat instances', function () {
+    Vue.config.strict = true
+    var vm = new Vue({
+      el: document.createElement('div'),
+      template: '<div v-repeat="list"><test></test></div>',
+      data: {
+        list: [1, 2]
+      },
+      components: {
+        test: {
+          template: 'hi'
+        }
+      }
+    })
+    expect(_.warn).not.toHaveBeenCalled()
+    expect(vm.$el.textContent).toBe('hihi')
+    Vue.config.strict = false
+  })
+
   it('class interpolation and v-class should work together', function (done) {
     var el = document.createElement('div')
     el.setAttribute('class', 'a {{classB}}')