Cleanup updateQueryString composable

This commit is contained in:
Kasper Seweryn 2022-04-23 10:09:40 +02:00 committed by Georg Krause
parent 41703f838f
commit 9fcc745e3c
No known key found for this signature in database
GPG Key ID: 2970D504B2183D22
2 changed files with 3 additions and 9 deletions

View File

@ -1,9 +1,5 @@
export default (uri: string, key: string, value: string) => {
const re = new RegExp(`([?&])${key}=.*?(&|$)`, 'i')
if (uri.match(re)) {
return uri.replace(re, `$1${key}=${value}$2`)
} else {
const separator = uri.indexOf('?') !== -1 ? '&' : '?'
return `${uri}${separator}${key}=${value}`
}
const url = new URL(uri)
url.searchParams.set(key, value)
return url.href
}

View File

@ -21,8 +21,6 @@ const app = createApp({
components: {
App: () => import('~/App.vue')
},
setup () {
},
data: () => ({ isMounted: false }),
async mounted () {
this.isMounted = true