vue3的script setup语法糖中toRefs如何优雅呈现

现在被迫这样写:

const state = reactive({
    time_type:'day',
    update_type:'auto', 
    day_frequency:1,
    month_frequency:1,
    date_selected:default7Days(),
    month_selected:defaultMonth(),
    indicator_list_initial:SHOP_INDICATOR,
})
const {time_type, update_type, day_frequency, month_frequency, date_selected, month_selected, indicator_list_initial} = toRefs(state)
阅读 12.7k
3 个回答
新手上路,请多包涵

reactive里再包一层?e.g.

<template>
  <p>{{ field.time_type }}</p>
  <p>{{ field.update_type }}</p>
  <p>{{ field.day_frequency }}</p>
</template>

<script>
...
setup() {
  const state = reactive({
    field: {
      time_type:'day',
      update_type:'auto', 
      day_frequency:1,
      month_frequency:1,
      date_selected:default7Days(),
      month_selected:defaultMonth(),
      indicator_list_initial:SHOP_INDICATOR,
    }
  })
  
  return {
    ...toRefs(state)
  }
},
...
</script>
新手上路,请多包涵

楼主有更好的办法吗

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏