0

I am doing a simple app that fetches data (my tasks) from my PocketBase(BaaS like Firebase).

I want to store my tasks into a ref because it could change overtime (ex: user modify the name of it).

I am supposed to get a simple array from my *getFullList() method, *but after that VueJS somehow wrap my value around a Proxy and I can not use the data inside.

I have tried storing my results in a non-ref variable and it worked, I simply had an array of my tasks into it.

But when using ref and the .value this Proxy comes around and I don't know why (its does not do this for my other ref like loading for eg.)

It probably is a stupid begginer mistake but i have read the doc again and again and cant seem to wrap my head around this :(

Here is the code of my MyTasks.vue and the console print statements

<script setup>
import { ref } from 'vue'
import { pb } from '../usePb'

const loading = ref(false)
const error = ref(null)
const myTasks = ref(null)

const fetchData = async () => {
  loading.value = true

  try {
    myTasks.value = await pb.collection('tasks').getFullList()
  } catch (err) {
    error.value = err.message
  } finally {
    loading.value = false
    console.log(myTasks.value)
    console.log(loading.value)
  }
}

fetchData()
</script>

enter image description here

  • I was excepting myTasks.value to hold an array instead of a proxy

  • I tried having my variable not ref, it worked but it is not what I want

  • Works fine with my other ref variables

5
  • Why is it a problem? Proxy is a sign that it's reactive, that's all. You shouldn't care about the way it's implemented in Vue as long as it works as expected. " it should hold a simple array" - no, it shouldn't, refs are deeply reactive, unless you use shallowRef Commented Oct 29, 2023 at 15:32
  • how can i access the array inside it then ? i read that proxy are not meant to be written inside. And why arent my other refs behaving this way ?
    – santoro
    Commented Oct 29, 2023 at 16:32
  • You didn't show how it's really used, because console.log isn't normal use. Again, you need to be generally aware about "proxy" thing but shouldn't care about it. Treat it as any other array, that's how it works. The whole question may be incorrect as it's unclear if there's really a problem to solve. It's unknown why something you didn't show doesn't behave like something you did show. As said, a value is automatically wrapped with a proxy when you assign it to a ref, unless you explicitly did something to prevent this Commented Oct 29, 2023 at 17:19
  • My bad in fact my problem came from my template ... sorry.
    – santoro
    Commented Oct 29, 2023 at 17:36
  • Glad you sorted this out. Yes, myTasks.value ref is auto-unwrapped to myTasks in a template Commented Oct 29, 2023 at 18:21

1 Answer 1

0

My bad my original post wasnt complete, my problem was that there were no tasks shown but it was because I used myTasks.value insteand of myTasks. And that it was i assumed my problem came from this proxy (which i read on an other post that the proxy want meant to be read). Thank you Estus FLask for your answers :)

1
  • Welcome to Stack Overflow! Thank you for your answer. Please provide more details about your solution. Code snippets, high quality descriptions, or any relevant information would be great. Clear and concise answers are more helpful and easier to understand for everyone. Edit your answer with specifics to raise the quality of your answer. For more information: How To: Write good answers. Happy coding!
    – AztecCodes
    Commented Oct 30, 2023 at 14:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.