[Vuejs]-How to dispatch a Vue computed property

0👍

You can try it declaring “ergebnis” as global variable under data as

export default {
  data () {
    return {
      subID: '',
      res: '',
      showAlert: true,
      varia: null,
      ergebnis : {}
    }
  },
  computed: {
    ...mapState([
      'FA',
      'Main',
      'Sub',
      'layouttype'
    ]),
    getVariable: function (Sub, layouttype) {
      const subID = this.layouttype.sub_id
      var filterObj = this.Sub.filter(function (e) {
        return e.sub_id === subID
      })
      console.log(filterObj)
      return filterObj
    },
    updateObject: {
      // getterfunction
      get: function () {
        var len = this.getVariable.length
        var res = []
        for (var i = 0; i < len; i++) {
          if (i in this.getVariable) {
            var val = this.getVariable[i].variable
            res.push(val)
          }
        }
        console.log(res)

        res.forEach(key => {
          if (this.FA[key]) {
            this.ergebnis[key] = this.FA[key]
          }
        })

        return this.ergebnis
      },
      // setterfunction
      set: function (value) {
        this.varia = value
      }
    }
  },
  methods: {
    submit () {
      this.$store.dispatch('sendData', this.ergebnis)
    }
  }
}

Now ergebnis is accessible

Leave a comment