在vue api组合中,应在反应式内部使用ref吗?

时间:2020-09-03 15:37:43

标签: vue.js vue-composition-api

reactive的vue api编写中,是否应该使用ref?一样吗ref会做什么?

const state = reactive({
  loading: ref(true)
});

const state = reactive({
  loading: true
});

1 个答案:

答案 0 :(得分:0)

您不需要这样做。 您可以只使用state.loading = something,它已经具有反应性。

但是请注意这一点。 state.loading = ture/false是反应性的,但 state = { loading: true/false }没有反应性,您可能会丢失反应性变量引用