#Watch value modified inside the watch

35 messages · Page 1 of 1 (latest)

grand matrix
#

Why couldn't you add the date when filling the ref through your API call? 🤔

solid wraith
#

because the api call could be call from multiple components

#

but maybe i should do it like that, anyway i found this solution :

#
  watch (experiments, (newExperiments) => {
    for (let i = 0; i < newExperiments.length; i++) {
      newExperiments[i].create_time = new Date(newExperiments[i].create_time).toDateString();
    }
    experiments.value = newExperiments;
    loading.value = false
    triggerTaskExperiments.value++
  })
#

Who is working for what i need

#

But maybe not the better one

#

I have another problem who is related more or less, let me explain :
Here is my onMounted : ```js
onMounted(() => {
nextTick(() => {
getExperiments()
})
})

This trigger the watch : ```js
 watch (experiments, (newExperiments) => {
    for (let i = 0; i < newExperiments.length; i++) {
      newExperiments[i].create_time = new Date(newExperiments[i].create_time).toDateString();
    }
    experiments.value = newExperiments;
    loading.value = false
    triggerTaskExperiments.value++
  })
``` who does     triggerTaskExperiments.value++
grand matrix
grand matrix
solid wraith
#

Then in my template i have : ```js
<TaskExperiments ref="task" :key="triggerTaskExperiments" :test="triggerTaskExperiments" :experiments="experiments" :infoUpload="infoUpload" v-on:refresh-task="receiveTaskRefresh" />

#

And receiveTaskRefresh function who actually is : ```js
function receiveTaskRefresh(info) {
analysis = info.analysis
}

#

And here what i got :

solid wraith
#

for all the entries

solid wraith
solid wraith
grand matrix
#

feels a bit like an X-Y problem here

#

do you get the new tasks via @refresh-task?

solid wraith
#

I've placed a console.log in receiveTaskRefresh function who is called by @refresh-task and it doesn't display

#

So i'm never inside this function, actually i'm not fully understanding how it should be triggering, or launched, it is related with the :key and :test props on the component ?

#

i found the @v-on on the docs but nothing about the refresh_task on the @v-on:refresh_task, it is something we can call whatever we want ?

#

But anyway, it was working before i was changing all the SFC from OptionsAPI to CompositionAPI, so it should be working 😦

grand matrix
#

there is no "built-in" refresh_task function

solid wraith
#

but the function name come after the v-on:refresh-task="hereIsTheFunctionCalled" no ?

#

refresh-task is the event ?

#

What would be the way to do that ?

solid wraith
#

in vue2 there is this

#

That's why

#

How can i do it in vue 3 ?

#

i can do it in vue3 too, my bad

#

i have this $emit("refresh-task") now who is calling @refresh-task="receiveRefreshTask" on my component

#

but the problem stay the same