[Vuejs]-Creating Vuex getters dynamically from database data

0👍

For anyone who is in a similar situation, I ended up importing an empty vuex module and caching it to a variable, assigning new getter functions and then registering it, similar to this:

import emptyVuexModule from 'emptyModule'

let cachedModule = emptyVuexModule

cachedModule.getters[getterName] = new Function(['state'], getterContents)

this.$store.registerModule(cachedModule)

I don’t know if this is the best solution and I know using new Function comes with security issues, but it works for my needs.

Leave a comment