【发布时间】:2020-12-22 21:28:15
【问题描述】:
在reactive在vue api组合中,我应该使用ref还是不使用?是一样的吗? ref 的作用是什么?
const state = reactive({
loading: ref(true)
});
或
const state = reactive({
loading: true
});
【问题讨论】:
标签: vue.js vue-composition-api
在reactive在vue api组合中,我应该使用ref还是不使用?是一样的吗? ref 的作用是什么?
const state = reactive({
loading: ref(true)
});
或
const state = reactive({
loading: true
});
【问题讨论】:
标签: vue.js vue-composition-api
您不需要这样做。
你可以使用state.loading = something,它已经是响应式的了。
但请注意这一点。
state.loading = ture/false 是被动的,但
state = { loading: true/false } 不是响应式的,您可能会丢失响应式变量引用
【讨论】: