How can i create a 2-D array define with the ref( ) function on vueJS?

147 views Asked by At

I want to create a 2-D array where the number of rows of the first dimension can be increased while clicking on a specific button.

<script setup>
...
//if define the table like that:
  var tab=ref([])
//this is the function called on the click
  function addrow(){
    tab.value.push()
    ...
  }
</script>
2

There are 2 answers

0
Alexander Nenashev On BEST ANSWER

You don't need to add a ref, the tab's value is already a reactive array, just add an array:

<script setup>
...
//if define the table like that:
  var tab=ref([])
//this is the function called on the click
  function addrow(){
    tab.value.push([])
    ...
  }
</script>

0
BradleyKANA On

i finally find the answer

<script setup>
...
//if define the table like that:
var tab=ref([ref([])])
//this is the function called on the click
function addrow(){
  tab.value.push(ref([]))
  ...
}
</script>