主题
useShare
响应式 Web Share API。浏览器提供可以分享文本或文件内容的功能。
🌐 Reactive Web Share API. The Browser provides features that can share content in text or file.
share方法必须在用户操作(例如点击按钮)之后调用。例如,它不能仅在页面加载时就调用。这是为了帮助防止滥用。
示例
用法
🌐 Usage
ts
import { useShare } from '@vueuse/core'
const { share, isSupported } = useShare()
function startShare() {
share({
title: 'Hello',
text: 'Hello my friend!',
url: location.href,
})
}传递源引用
🌐 Passing a source ref
你可以传入一个 ref,源引用的更改将会反映到你的共享选项中。
🌐 You can pass a ref to it, changes from the source ref will be reflected to your sharing options.
ts
import { ref } from 'vue'
const shareOptions = ref<ShareOptions>({ text: 'foo' })
const { share, isSupported } = useShare(shareOptions)
shareOptions.value.text = 'bar'
share()js
import { ref } from 'vue'
const shareOptions = ref({ text: 'foo' })
const { share, isSupported } = useShare(shareOptions)
shareOptions.value.text = 'bar'
share()