Skip to content

useGetUrlParam

Introduction

获取URL参数中指定参数值

Basic Usage

ts
import { useGetUrlParam } from '@flypeng/tool/browser';

// 获取本地的参数
const param1 = useGetUrlParam('name');

// 获取指定字符串的参数
const param2 = useGetUrlParam('name', '?name=@flypeng/tool&description=工具库');
const param3 = useGetUrlParam('description', '?name=@flypeng/tool&description=工具库');

Online Demo

useGetUrlParam
获取 URL 参数中指定参数值
获取当前地址的参数name: 不存在此参数
获取: 不存在此参数
获取: 不存在此参数
<script lang="ts" setup>
import { useGetUrlParam } from '@flypeng/tool/browser';

const customParams = '?name=@flypeng/tool&description=工具库';
</script>

<template>
  <div>
    <section>
      获取当前地址的参数name:
      {{ useGetUrlParam('name') || '不存在此参数' }}
    </section>
    <section>
      获取<label style="color: var(--vp-c-brand)">{{ customParams }}</label
      >:
      {{ useGetUrlParam('name', customParams) || '不存在此参数' }}
    </section>
    <section>
      获取<label style="color: var(--vp-c-brand)">{{ customParams }}</label
      >:
      {{ useGetUrlParam('description', customParams) || '不存在此参数' }}
    </section>
  </div>
</template>

Type Declaration

ts
/**
 * 获取URL参数中指定参数值
 * @param param
 * @param origin
 * @returns
 */
declare function useGetUrlParam(param: string, origin?: string): string | null;

Released under the MIT License.