我想创建一个2-D数组,其中第一维的行数可以在单击特定按钮时增加.

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

推荐答案

不需要加引用,tab‘S值已经是无功数组了,加一个数组就行了:

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

Vue.js相关问答推荐

虚拟DOM在Vue中姗姗来迟

保持页面重新加载之间的状态

作为props 传递的原始 ref 的 Vue 3 react 性

在 v-for 中定义变量有什么问题吗?

处理多张卡片中的按钮

nuxt.js auth 始终重定向到登录,而不是允许转到带有 auth: false 的页面,

如何在vue中获取特定类别的产品列表

Vue 脚本标签中更漂亮的 destruct 功能

使用 jquery-chosen 插件更新 vuejs 模型值

如何从 Vuex 状态使用 Vue Router?

为什么 Vue 路由/Webpack 开发服务器现在在页面刷新时显示无法获取/路径?

如何为使用 Vuex store的 Vue 表单组件编写 Jest 单元测试?

CLI 3 - 如何为 CSS/Sass 创建vendor bundle ?

如何像 React 中的 {...props} 一样在 Vue 中解构 props?

NuxtServerInit 在 Vuex 模块模式下不起作用 - Nuxt.js

Amazon EC2 错误:监听 EACCES 0.0.0.0:80

vuex - 即使不推荐,是否可以直接更改状态?

Vuejs 组件等待 facebook sdk 加载

在 Vuejs 中全局导入 Axios 方法

禁用外部主题文件产生的 Dart SASS 警告