Problem vue-meteor-tracker on Vue Composition API?

I try to use Vue composition api.
And get current user in meteor tracker

// Template
{{ currentUser }}

// JS
setup(props, { root: { $autorun } }) {
    const currentUser = computed(() => {
       return $autorun(() => Meteor.user())

    return {currentUser}

But don’t work, please help me

Unfortunately the new Vue Composition API breaks the current Meteor/Vue code (the akryum stuff).

I found a way of doing this, which works perfectly well.
I set up a ref() to hold the current user, then I put this code in setup():

           Tracker.autorun(() => {
                signInStuff.currentUserId.value = Meteor.userId();

UPDATE: I’ve changed this to only save the user id, because it’s not good practice to save the whole user record, as they tend to fill up with large amounts of stuff.

1 Like

Very thanks, It work fine.

Glad you guys were able to make this work :grinning: :+1: @akryum mentioned that he will be making updates for Vue 3+ (Composition API, etc), but I would not expect to see this until Vue 3 is out of beta for a bit. Kind of how Meteor doesn’t release Node.js, MongoDB, and Cordova updates at every cycle, it’s better to wait for stability before making integration updates that impact everyone.

But incase others want to play around with Vue 3 in beta with Meteor, this could be helpful. If you want to share your fork of the vue-meteor-tracker package with the community here, maybe others would benefit.

I’m in no rush to use any Composition API features from Vue 3 because I kind of really like the current Vue coding style. It just works for me.

1 Like

Thanks for keeping us informed @mullojo. That’s really good news that Guillaume will be working on it.

I haven’t forked the vue-meteor-tracker package yet, I’ve simply worked around problems by working directly with Meteor code, which clearly is not so neat as the akryum solutions.

For what it’s worth, I love the Composition API. I’ve installed it as an addon to Vue 2.

It has transformed my code, allowing me to group stuff together that belongs together, making everything so much clearer.
It also takes you back to bare javascript which makes it easier to test now that the this variable has gone.
And finally it is much easier to use Typescript than solutions like the Class API.