meteor-vue / vue-meteor-tracker

Use Meteor Tracker reactivity inside Vue components
90 stars 20 forks source link

Pass variable into MeteorData's query #44

Closed nilsi closed 6 years ago

nilsi commented 6 years ago

Hi,

Thanks for som great updates to this libraray.

Im trying to do this:

<div class="column" v-for="id in data.listItems" :key="id">
    <MeteorSub name="productByReadableId" :parameters="[parseInt(id)]" >
        <template slot-scope="{ loading }">
            <MeteorData
                :query="getProduct(id)"
                class="product">
                <template slot-scope="{ data: product }">
                    {{product}}
                </template>
            </MeteorData>
        </template>
    </MeteorSub>
</div>

And then:

  methods: {
   ...
    getProduct(id) {
      return Products.findOne({ readableId: id });
    }
  },

Which gives me the following error: Invalid prop: type check failed for prop "query". Expected Function, got Undefined

If I remove the parameter and hardcode my id in the findOne function it works as I expected. Is there any way to pass a variable into my getProduct function?

nilsi commented 6 years ago

I just redesigned my code and passed my id into a product component where I subbed and rendered the product. That's probably what I should have done from the beginning.