0

I've got dynamic component:

<component v-bind:is="current.ComponentName" :myvar="current.Text"></component>

where I'm trying to pass variable myvar for the currently resolved component.

Subcomponent is defined like so:

    <template>
        <div id="home">
            <h1>2 {{ myvar }} aasa</h1>
        </div>
    </template>

    <script>
        Vue.component(
            'MyComponentName',
            {
                props: ['myvar']
            });
    </script>

Dynamic component resolving works but I can't get manage to pass any data via :myvar=.... How can I do that?

Puchacz
  • 1,987
  • 2
  • 24
  • 38

1 Answers1

1

I'm sorry if I misunderstand your question, it's not that clear, if I did you let me know in the comments and I will edit my answer. Also your question is not really complete


I think you misunderstood the difference between a single file component and a Vue.component

You must choose one or the other, You can not mix both.

Eighter you define your component like this:

<template>
  <div id="home">
        <h1>2 {{ myvar }} aasa</h1>
    </div>
 </template>

<script>
export default {
  props: ["myvar"] 
}
</script>

or like this:

Vue.component("component-name", {
  props: ["myvar"], 
  template:`
    <div id="home">
        <h1>2 {{ myvar }} aasa</h1>
    </div>
  `
})

Documentation link: https://v2.vuejs.org/v2/guide/components.html

tony19
  • 125,647
  • 18
  • 229
  • 307
Patrick Hollweck
  • 5,604
  • 2
  • 19
  • 34
  • Thank you, It looks like mixing both of declaring `Vue.component` with `export default` made it wasn't working. It works after I chose a single way. – Puchacz Aug 25 '18 at 16:29