export function useRoomUsers(roomId) {
let executorList = ref([])
RoomApi.findRoomUsers({roomId}).then(res => {
executorList.value = res.data;
})
return { executorList }
}
// const { executorList } = useRoomUsers(11)
// console.log('executorList', executorList)
let executorList = ref([])
watch(() => searchForm.roomId, (val) => {
if (val) {
executorList.value = useRoomUsers(val).executorList
console.log('executorList', executorList)
}
})
return { executorList }
useRoomUsers是一个异步获取数据方法返回ref对象,用解构方式获取的数据是可以正常响应的。
但业务需要放在watch当中就不行了。试过把返回的地方改成reactive 直接这边数组都是空的,理解不了,求大神指点。
就很奇怪获取value是空的,但打印出来数组是有数据的
改成这样可以了,之前直接用的searchForm.value.roomId不会触发watchEffect,后面的判断也得用unref解包。说实话还是疑惑除了解构方式 直接value赋值为啥不行。