Search code examples
arraysvue.jsvuejs3-composition-api

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


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>

Solution

  • 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>