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

    q-toggle local storage toggle problem. how to solve it?

    Help
    3
    4
    150
    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.
    • A
      avijit526 last edited by

      Show Video

      <q-toggle
                    :false-value="false"
                    :label="` ${redModel} `"
                    :true-value="true"
                    color="red"
                    v-model="redModel"
                    @input="test"
                  />
      
      data() {
          return {
               redModel: false
            }
      },
      
      methods: {
          test(val) {
            this.redModel = val
            console.log(this.redModel)
            localStorage.setItem("redModel", this.redModel);
          }
        },
      
        mounted() {
          this.redModel = localStorage.getItem("redModel")
        },
      
      beets dobbel 2 Replies Last reply Reply Quote 0
      • beets
        beets @avijit526 last edited by beets

        @avijit526 Localstorage can only store strings. Try changing your mounted method to:

          mounted() {
            this.redModel = localStorage.getItem("redModel") === "true"
          },
        

        Edit: Or, you could use:

                      false-value="false"
                      true-value="true"
        

        Note that there isn’t a colon, so its true and false values are the literal strings “true” and “false”. But this isn’t the better solution IMO.

        A 1 Reply Last reply Reply Quote 0
        • dobbel
          dobbel @avijit526 last edited by dobbel

          @avijit526 @beets

          The localstorage of a browser only supports strings as mentioned by @beets.

          But you can use Quasar’s LocalStorage plugin that supports Objects.

          https://quasar.dev/quasar-plugins/web-storage#LocalStorage-API

          1 Reply Last reply Reply Quote 1
          • A
            avijit526 @beets last edited by

            @beets Thanks

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