if(window.location.href.includes('part_category_tags[]=2')) {
this.checkedCategories.push(2);
}
Needed: depending on what the number is next to the part_category_tags[]= parameter, push this number into the array.
also, it may be that such a parameter occurs twice like (Or not be at all):
&part_category_tags[]=3&part_category_tags[]=2
Without vue-router
You can just loop through the params.
const url = new URL('https://fake.domain.name/?fake=query&part_category_tags[]=3&part_category_tags[]=2'); // document.location instead of fake utl.
let params = url.searchParams;
params.forEach((v,q) => console.info(q, v)); // just output queries and values
params.forEach((v,q) => { if (q === 'part_category_tags[]' && v === '2') { console.info('Pushing the 2') } });
// params.forEach((v,q) => { if (q === 'part_category_tags[]' && v === '2') { this.checkedCategories.push(v); } });
Updated with numberless code.
// // use document.location instead of fake url.
const url = new URL('https://fake.domain.name/?fake=query&part_category_tags=3&part_category_tags=2');
let params = url.searchParams;
params.forEach((v,q) => { if (q === 'part_category_tags') { console.info(`Pushing the ${v}`) } });
// params.forEach((v,q) => { if (q === 'part_category_tags') { this.checkedCategories.push(v); } });