reactjsvue.jsvue-component

Reacts this.props.children in vue.js component


React has something like this.props.children: https://facebook.github.io/react/tips/children-props-type.html

Does Vue.js have also some similar to access the child-elements?


Solution

  • In your requirement:

    Using slot is a right way to pass a custom component into the child component, when you are in the parent component level.

    But why doesn't it work? Because in Vue 1.0, it uses the browser to parse the template, not virtual DOM. Browser-parsing has a problem: some HTML elements have restrictions on what elements can appear inside them.

    see Vue1.0 Doc: vue1.0 - components - template parsing

    And you happen to make that mistake.

    This is a limitation in Vue1.0, you have to write some Directives to do them.

    But in Vue 2.0, things have changed, the template-parsing became a virtual-dom implement. You can pass any DOM elements into slot.

    I try your link in last comment with Vue 2.0, it works.

    Just change the External Resources to https://unpkg.com/vue@2.0.1/dist/vue.js