【问题标题】:In vue api composition should I use ref inside reactive?在 vue api 组合中,我应该在反应性中使用 ref 吗?
【发布时间】: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


    【解决方案1】:

    您不需要这样做。 你可以使用state.loading = something,它已经是响应式的了。

    但请注意这一点。 state.loading = ture/false 是被动的,但 state = { loading: true/false } 不是响应式的,您可能会丢失响应式变量引用

    【讨论】:

      猜你喜欢
      • 2021-12-29
      • 1970-01-01
      • 2022-11-27
      • 2021-11-05
      • 1970-01-01
      • 2022-01-03
      • 2022-07-27
      • 2021-06-11
      • 1970-01-01
      相关资源
      最近更新 更多