No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    How to implement simple state?

    Help
    2
    3
    802
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      gusi1994 last edited by

      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.

      1. Where should I import my store.js?
      2. How can I use it inside my components? (How can I emit the events for changing the state)
      1 Reply Last reply Reply Quote 0
      • benoitranque
        benoitranque last edited by

        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)
            }
          }
        }
        
        G 1 Reply Last reply Reply Quote 0
        • G
          gusi1994 @benoitranque last edited by

          @benoitranque Thank you very much. You helped me a lot!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post