Vue: dynamic component with props passing issue

Created on 16 Oct 2015  ·  7Comments  ·  Source: vuejs/vue

I create some dynamic components with a sample router, but when I change the currentView value to render the component, there are some warn message print like:
Data field "xxx" is already defined as a prop. Use prop default value instead.
obviously, I passed the parent data by props

with Vue.js 1.0.0-alpha.8

need repro

Most helpful comment

Declaring props is enough. No need to duplicate them in data.

All 7 comments

@ije having a code example would be helpful...

sorry, there are so many lines in my project, i just can paste the keypart of the dynamic component:

template look like this:

<component v-bind:is="currentPageEditView" v-bind:editing-page="editingPage" v-bind:editing-post="editingPost" v-bind:editing-content="editingContent"></component>

the parent vm config look like this:

{
  template: 'blabla...',
  data: function() {
    return {
      // other fields..
      currentPageEditView: null,
      editingPage: null,
      editingPost: null,
      editingContent: null
    };
  },
  components: (function() {
    var components = {};
    utils.each(config.postPageComponents, function(component) {
      // component preprocess
      component.props = ['editingPage', 'editingPost', 'editingContent'];
      components[component.id] = component;
    })
    return components;
  })(),
  methods: {
    editPost: function(post) {
      this.editingPost = post;
    },
    editPage: function(page) {
      this.editingPage = page;
    },
    editContent: function(content) {
      this.editingContent = content;
    }
  }
}

and the config.postPageComponents look like this:

var config = {
  postPageComponents: [
    {
      template: 'blabla...',
      id: 'component-id',
      name: 'Name',
      data: function(){},
      method: {},
      // blabla..
    },
    // more components define
  ]
};

sorry, I forget note that the parent vm is also a dynamic component...

@karevn thank you!

there is a screen shot of console warn messages.
screen shot 2015-10-17 at 15 16 48

@ije, it's "by design" behavior in new versions. If you need to have some default values for your props, just pass them in your prop config.

Declaring props is enough. No need to duplicate them in data.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

loki0609 picture loki0609  ·  3Comments

aviggngyv picture aviggngyv  ·  3Comments

guan6 picture guan6  ·  3Comments

wufeng87 picture wufeng87  ·  3Comments

bdedardel picture bdedardel  ·  3Comments