Vuex - используйте ключевое слово this в состоянии для доступа к методу в дочернем компоненте - PullRequest
2 голосов
/ 26 февраля 2020

Я работаю с Vue (+ Vuetify) и Vuex. В магазине> состояние у меня есть вложенный объект. Отображение его в дочернем компоненте работает, как и ожидалось, но внутри объекта я пытаюсь получить доступ к методу child component с помощью this.row и this.hidden. Это приводит к

Uncaught TypeError: Невозможно прочитать свойство 'row' из undefined.

Ниже приведен код из хранилища и дочернего компонента.

// store.js

const state = {
    myValue: {
        radioRequesttype: "New Registration",
        numberInfo: [{ sNumber: '' }]
    },
    mySchema: {
        radioRequesttype: {
            type: "radio",
            row: this.row,
            options: ["New Registration", "Re-registration"]
        },
        sNumberInfo: {
            hidden: this.hidden,
            type: "array",
            flex: 12,

            schema: {
                sNumber: {
                    type: "text",
                    label: "ID",
                    hint: "by re-registration only",
                    flex: 12
                }
            }
        }
    }
};
// childcomponent.vue

  computed: {
    ...mapGetters ([
        'myValue',
        'mySchema'
    ]),
    row() {
      return this.$vuetify.breakpoint.mdAndUp;
    }
  },
  methods: {
    update(val) {
      update(val);

      let { key, value } = val;

      if (key === "radioRequesttype")
        this.mySchema.sNumberInfo.hidden = value !== "Re-registration";
    },
      ...mapActions ([
          'updateMyValue'
      ])
  }
...