跳到主要内容

useQRCode

分类
导出大小
403 B
@vueuse/integrations
上次更改
8 个月前

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" />

类型声明

ts
/**
 * 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>

来源

源代码演示文档

贡献者

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

更新日志

v12.8.0
7432f - feat(types): 废弃 MaybeRefMaybeRefOrGetter,转而使用 Vue 的原生类型 (#4636)
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)

根据 MIT 许可证发布。