【问题标题】:How to add a module getters in composition api?如何在组合 API 中添加模块吸气剂?
【发布时间】:2021-04-21 03:47:16
【问题描述】:

我正在使用 vue 2,安装了 composition api。如何添加 Getter? 通常:

  computed: {
...mapGetters("Auth", ["isLogged"])}

.................................................. ....................

setup() {
const title_app = ref("Name App");
const logout = () => {
  store
    .dispatch("Auth/logout")
    .then(() => {
      router.push({ name: "About" });
    })
    .catch((err) => {
      console.log(err);
    });
};

return {
  title_app,
  logout,
};

},

【问题讨论】:

    标签: vuejs2 vue-composition-api


    【解决方案1】:

    你可以这样做:

    import { computed } from 'vue'
    
    export default {
      setup (props, { root }) {
        const isLogged = computed(() => root.$store.Auth.getters.isLogged)
    
        return {
          isLogged
        }
      }
    }
    

    【讨论】:

    • "TypeError: root.$store.Auth 未定义"
    • 尝试调试它,它的哪一部分未定义。
    猜你喜欢
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 2023-02-02
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    • 2018-11-16
    相关资源
    最近更新 更多