Skip to content

Passing data to Components is overly complicated - in common, simple examples #1987

@FEA5T

Description

@FEA5T

Setup

Vue.component('bars', {
    template: '#bars-template', // is this even necessary? just pickup all "x/template" 's automatically and infer the name from the id?
})
<script type="x/template" id="bars-template">
    <svg>
        <g v-for="pt in pts">
            <rect x="{{pt.x}}" y="{{pt.y}}" width="{{z}}" height="{{z}}"></rect>
        </g>
    </svg>
</script>

Instance

var d = {
    pts: [{x: 1, y:2}, {x: 3, y:4}],
    z: 2
}

var v = new Vue({
    el: "#graph", // this should pass the data into all child templates automatically
    data: d
})

Why do I have to pass data down in my html elem? Why doesn't it have access to the Vue instance that it is a child of like normal html would?

<div id="graph">
    <bars :pts="pts"></bars>
</div>

So that I can do this:

<div id="graph">
    <bars></bars>
</div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions