Explorar o código

warn against incorrect propsData usage

Evan You %!s(int64=10) %!d(string=hai) anos
pai
achega
c94d04da46
Modificáronse 2 ficheiros con 14 adicións e 0 borrados
  1. 5 0
      src/util/options.js
  2. 9 0
      test/unit/specs/directives/internal/prop_spec.js

+ 5 - 0
src/util/options.js

@@ -325,6 +325,11 @@ function guardArrayAssets (assets) {
 export function mergeOptions (parent, child, vm) {
   guardComponents(child)
   guardProps(child)
+  if (process.env.NODE_ENV !== 'production') {
+    if (child.propsData && !vm) {
+      warn('propsData can only be used as an instantiation option.')
+    }
+  }
   var options = {}
   var key
   if (child.mixins) {

+ 9 - 0
test/unit/specs/directives/internal/prop_spec.js

@@ -615,6 +615,15 @@ describe('prop', function () {
     expect(vm.a).toBe(123)
   })
 
+  it('should warn using propsData during extension', function () {
+    Vue.extend({
+      propsData: {
+        a: 123
+      }
+    })
+    expect('propsData can only be used as an instantiation option').toHaveBeenWarned()
+  })
+
   it('should not warn for non-required, absent prop', function () {
     new Vue({
       el: el,