skip to Main Content

How to access to the query parameters in laravel + inertia vue js.?

<script>
  export default {
  computed: {
   reference() {
    return this.$page.props.query.reference || 'No reference provided';
   }
  }
 };
</script>

2

Answers


  1. Chosen as BEST ANSWER

    We can access using this way. its working for me.

    <script>
     let params = new URLSearchParams(window.location.search)
     console.log(params.get('YourParam))
    </script>
    

  2. You could do something like this:

    function $route() {
        const query = {};
    
        const url = new URL(this.$page.url, window.location.origin);
    
        for (const [key, value] of url.searchParams.entries()) {
            query[key] = value;
        }
    
        return {
            origin: window.location.origin,
            path: url.pathname,
            fullUrl: url,
            query,
        };
      }
    }
    

    This can then be injected via mixins or better still you can make it a composable.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search