Unable to make Vuex getters etc. work with – tony19 Aug 22 '21 at 01:27

  • You are right, it actually does work. But Vetur fooled me, it shows unreturned variables as unused, so it looked to me that was the reason it wasn't picked up in the template. But it was an unrelated error that was the real reason. Because of this Vetur problem I'll stick with the older setup syntax for now. – anatolhiman Aug 22 '21 at 03:41
  • 1
    Try to use the vuedx extension https://marketplace.visualstudio.com/items?itemName=znck.vue-language-features – Boussadjra Brahim Aug 22 '21 at 07:18
  • 2 Answers2

    3

    I kept trying and

    import { computed } from 'vue';
    import { useStore } from 'vuex';
    
    const store = useStore();
    
    const con = computed(() => store.getters.connected);
    

    In this case connected is just a boolean but I also tried it with objects and it still works.

    My template:

    <template>
      <h1>{{ con }}</h1>
    </template>
    

    And it works just fine.

    h0p3zZ
    • 690
    • 3
    • 16
    • You are right, my code actually did work. But Vetur fooled me, it shows those unreturned variables as unused, so it looked to me like that was the reason it wasn't picked up in the template. But it was an unrelated error that was the real reason. Because of this Vetur problem I'll stick with the older setup syntax for now. Thanks for investigating! – anatolhiman Aug 22 '21 at 03:43
    1

    Your usage in <script setup> actually works, but as pointed out in comments, the Vetur VS Code extension was showing misleading errors.

    As of 0.34.1, Vetur does not support <script setup>. The recommended extension for <script setup> is Volar. This was even tweeted yesterday from Vue's official Twitter account:

    tweet

    tony19
    • 125,647
    • 18
    • 229
    • 307