Skip to content

createUnrefFn

类别
导出大小
101 B
最近修改
2 days ago
相关

创建一个普通函数,接受 ref 和原始值作为参数。返回与未转换函数相同的值,并具有正确的类型。

🌐 Make a plain function accepting ref and raw values as arguments. Returns the same value the unconverted function returns, with proper typing.

TIP

确保你使用的是适合该工作的工具。在某些情况下,如果你想在每次参数变化时评估函数,使用 reactify 可能更合适。

用法

🌐 Usage

ts
import { 
createUnrefFn
} from '@vueuse/core'
import {
shallowRef
} from 'vue'
const
url
=
shallowRef
('https://httpbin.org/post')
const
data
=
shallowRef
({
foo
: 'bar' })
function
post
(
url
,
data
) {
return
fetch
(
url
, {
data
})
} const
unrefPost
=
createUnrefFn
(
post
)
post
(
url
,
data
) /* ❌ Will throw an error because the arguments are refs */
unrefPost
(
url
,
data
) /* ✔️ Will Work because the arguments will be auto unref */