79455788

Date: 2025-02-20 20:41:49
Score: 1
Natty:
Report link

If you're using the module Vue Router, the following answer might be helpful to you: https://stackoverflow.com/a/35916241/23561820

Summary (with Vue Router)

With the usage of the route object, a query in the URL can be retrieved as such:

URL

http://somesite.com?test=yay

Code

const test = this.$route.query.test;
console.log(test); // outputs 'yay'

If you'd prefer not to use the library Vue Router, you may find the answer below useful: https://stackoverflow.com/a/901144/23561820

Summary (without Vue Router)

Using URLSearchParams, a query in the URL can be acquired like so:

URL

http://somesite.com?test=yay

Code

const urlParams = new URLSearchParams(window.location.search);
const test = urlParams.get('test');
console.log(test); // outputs 'yay'
Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: NaBrHCl