How to implement simple state?
-
Hello everybody,
i’m new to quasar and now I need to implement a simple state. Vuex is an option but it is too much for my needs.
I don’t no where to import my store.js. Currently this is my store.js:
//This is store.js export default { store: { state: { message: 'Hello!' }, duplicateMessage: function() { this.state.message += this.state.message; }, halfMessage: function() { this.state.message = this.state.message.substr(0, this.state.message.length/2); } } }
So I have two questions and I hope anyone can help me with this simple question.
- Where should I import my store.js?
- How can I use it inside my components? (How can I emit the events for changing the state)
-
Simplest store:
export default { message: '' }
use in component/anywhere
import store from './store' // make sure this points to the correct relative path export default { methods: { met () { store.message = 'hello world' } } }
another component:
import store from './store' export default { methods: { met () { console.log(store.message) } } }
-
@benoitranque Thank you very much. You helped me a lot!