Vue.js query parameters

Vue.js query parameters

Asked on November 13, 2018 in vue.js.
Add Comment


  • 2 Answer(s)

    Here the brief solution,

    <script src="siteurl"></script>
    var router = new VueRouter({
        mode: 'history',
        routes: []
    });
    var vm = new Vue({
        router,
        el: '#app',
        mounted: function() {
            q = this.$route.query.q
            console.log(q)
        },
    });
    
    Answered on November 13, 2018.
    Add Comment

    You can split URLs without using vue-route

    var vm = new Vue({
      created()
      {
        let uri = window.location.href.split('?');
        if (uri.length == 2)
        {
          let vars = uri[1].split('&');
          let getVars = {};
          let tmp = '';
          vars.forEach(function(v){
            tmp = v.split('=');
            if(tmp.length == 2)
            getVars[tmp[0]] = tmp[1];
          });
          console.log(getVars);
          // do
       }
      },
      updated(){
      },
    
    Answered on November 13, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.