Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
Vuex import local JSON file into state

I want to import data from my local JSON file into a state value setting.

store/index.js

import { createStore} from 'vuex'

export default createStore({
  state: {
    settings: {}
  }
})

assets/json/settings.json

{
  "theme": "dark",
  "loggedIn": true,
  "mobile": false,
}

It also has to be reactive to work with computed in Vue. This means it should use maybe something like fs or so to save the changes into the JSON file. I use Vuex because I want to change data across multiple components.

How I can set the JSON value into the state.settings value? 😅

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

you can import directly from a json file like you would a js file

which you can then return from the state initialiser

import settings from "./settings.json";
export default createStore({
  state(){ //note: state should always be a function to create a state not the state itself
    return {
       settings: settings
    }
  }
})

just be sure you have

"resolveJsonModule": true

in your js compiler options

the browser shouldn't be editing this file directly so save changes in a cookie, local storage,session storage, or via a webservice call to your server

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda