Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

How to access to a ref value ?

Hello,

The documentation shows how to access to a ref value.

const title = ref('my first super title')

title.value = 'my second super title'

this.title = 'my third super title'

this.title seems to work, I just tested it with pinia.

So is there really two ways to access to the value .value and this. ?

I specify that I have tested both in composition API mode.

Thanks for your answer.

V

0 likes
3 replies
vincent15000's avatar

@martinbean Here is the code. Have a look at the lines where I modify the can_create property.

But why levels.value works whereas can_create.value doesn't work ?

import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import apiLevel from '@/services/apiLevel'

export const useLevelStore = defineStore('level', () => {
  const levels = ref([])
  const levels_select = ref([])
  const form = ref({})
  const can_create = ref(false)
  const show_dialog = ref(false)

  ...

  function loadIndex() {
    apiLevel.index().then(response => {
      levels.value = response.data.levels
      this.can_create = response.data.can_create // WORKS
      can_create.value = response.data.can_create // DOESN'T WORK
    })
  }

  ...
  
  return {
    levels,
    levels_select,
    form,
    show_dialog,
    showDialog,
    loadForm,
    save,
    reset,
    loadIndex,
    loadSelect,
    create,
    store,
    edit,
    update,
    destroy,
  }
})

Please or to participate in this conversation.