vue-meteor-tracker icon indicating copy to clipboard operation
vue-meteor-tracker copied to clipboard

Options API: functions in meteor object cannot access other properties

Open rickynaps opened this issue 1 year ago • 1 comments

<script>
  export default {
    data() {
      return {
        selectedThreadId: 'test',
      };
    },
    computed: {
      testComputed() {
        return 'testComputed';
      },
    },
    meteor: {
      $subscribe: {
        threads: [],
      },
      meteorTestComputed() {
        // returns undefined
        return this.testComputed;
      },
      testSubReady() {
        // this.$subReady.threads == undefined
        if (this.$subReady.threads) {
          console.log('test If');
        }
      },
      threads() {
        //  Works as expected.
        return Threads.find(
          {},
          {
            sort: { date: -1 },
          }
        );
      },
      threadsTest() {
        // Returns undefined
        return this.threads;
      },
      selectedThread() {
        // Doesn't work as expected.
        const test = this.selectedThreadId;
        // test == undefined
        // The same happens with properties in computed and meteor sections.
        return Threads.findOne(this.selectedThreadId);
      },
    },
  };
</script>

<!-- 
computed
can access meteor properties
cursor is not reactive

meteor
cursor is reactive
cannot access computed, meteor or data properties
can access this correctly -->

rickynaps avatar Jun 13 '23 23:06 rickynaps

Same here, with:

  • vue 3.3.4
  • meteor 2.12

We can't access data or computed properties inside the meteor block.

I had to change the component to composition API

xolott avatar Aug 17 '23 21:08 xolott