在globalProperties上挂载的响应式属性,在template中必须使用.value获取 #7405
Answered
by
liulinboyi
anchogin
asked this question in
Help/Questions
-
在vue3可以挂载一个全局属性app.config.globalProperties,但是当这个属性是响应式的,在template中使用的时候需要.value才能获取,有什么办法可以规避.value吗,在data,或prop中的是不需要.value,那位大神可以帮忙解惑 |
Beta Was this translation helpful? Give feedback.
Answered by
liulinboyi
Dec 23, 2022
Replies: 1 comment 3 replies
-
If you want to auto unref, I suggest use: import { resolveUnref } from '@vueuse/core'
const foo = ref('hi')
const a = resolveUnref(0) // 0
const b = resolveUnref(foo) // 'hi'
const c = resolveUnref(() => 'hi') // 'hi' Or ...
const app = createApp(App)
app.config.globalProperties = reactive({ msg: ref('hello') })
... let the globalProperties is a Reactivity value. |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
anchogin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to auto unref, I suggest use:
Or
let the globalProperties is a Reactivity value.