跳到内容

useQRCode

类别
导出大小
401 B
@vueuse/integrations
最近更改
5 天前

qrcode 的封装。

演示

QRCode 的文本内容
QR Code
@vueuse/integrations 附加组件中可用。

安装

bash
npm i qrcode@^1

用法

ts
import { useQRCode } from '@vueuse/integrations/useQRCode'

// `qrcode` will be a ref of data URL
const qrcode = useQRCode('text-to-encode')

或将 ref 传递给它,返回的数据 URL ref 将随源 ref 的更改而更改。

ts
import { useQRCode } from '@vueuse/integrations/useQRCode'
import { shallowRef } from 'vue'

const text = shallowRef('text-to-encode')
const qrcode = useQRCode(text)
html
<input v-model="text" type="text" />
<img :src="qrcode" alt="QR Code" />

类型声明

typescript
/**
 * Wrapper for qrcode.
 *
 * @see https://vueuse.org.cn/useQRCode
 * @param text
 * @param options
 */
export declare function useQRCode(
  text: MaybeRefOrGetter<string>,
  options?: QRCode.QRCodeToDataURLOptions,
): ShallowRef<string, string>

源码

SourceDemoDocs

贡献者

Anthony Fu
IlyaL
Anthony Fu
Doctorwu
Curt Grimes
Okuto Oyama
Alex Kozack
Antério Vieira

更新日志

v12.8.0 on 3/5/2025
7432f - feat(types): deprecate MaybeRef and MaybeRefOrGetter in favor of Vue's native (#4636)
v12.0.0-beta.1 on 11/21/2024
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
10e98 - feat(toRef)!: rename resolveRef to toRef

在 MIT 许可证下发布。