How to use Object.value in Vuex Getters module

Asked

Viewed 98 times

0

in a. Vue or Vue html file, I can use a v-if with the following snippet

Object.values(this.dialogs).filter((v) => v).length !== 0

and works as expected but in a file. js more precisely in a vuex getter type file there is an error when compiling that Object is not solved, inserir a descrição da imagem aqui

my Vuex pagination file is this for this case

import Vue from 'vue'
import Vuex from 'vuex'

import Modules from '@/plugins/vuex/modules'

Vue.use(Vuex)

export default function () {
  const Store = new Vuex.Store({
    strict: process.env.NODE_ENV !== 'production',
    modules: {
      Modules
    }
  })
  return Store
}

and Modules is this

import state from '@/plugins/vuex/state'
import * as getters from '@/plugins/vuex/getters'

export default {
    namespaced: true,
    state,
    getters
}

in case, how can I do that

const dialogs = (state) => {
  // isso aqui
  return Object.values(state.dialogs).filter((v) => v).length !== 0
  // isso aqui
}

export {
  dialogs
}

at getter?


Okay, I did it in this format until I got a better response

const dialogs = (state) => {
  function Object (object) {
    for (var i in object) { if (object[i]) return false }
    return true
  }
  return Object(state.dialogs)
  // return Object.values(state.dialogs).filter((v) => v).length !== 0
}

it is not so beautiful but it works, if there is a more beautiful and smaller form as in the example that works in . See, I prefer

  • In the second code snippet (getter Vuex), which appears if you give a console.log(state.dialogs)?

  • @Luizfelipe works normally by displaying all dialogs within the dialog object, in my case dialog: { States: false, loading: false, popup: false }; what about the error is Object.values that shows how to install

  • It would be nice if you post the Vuex code more complete than just the section you want to include.

  • Vuex works with modules, I am using a module called for such a task, this has only this section defined for getters, however, I can attach the main without problems

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.