vue新建数组并追加元素
时间: 2024-02-02 20:06:54
浏览: 39
在Vue中,可以通过以下[方式]([http]([http](https://geek.csdn.net/educolumn/68f28ca3131d47699e5902c5d3d74d51?spm=1055.2569.3001.10083)s://geek.csdn.net/educolumn/68f28ca3131d47699e5902c5d3d74d51?spm=1055.2569.3001.10083)s://geek.csdn.net/educolumn/0a7fca90472e8d39fd3078246e0b14f3?spm=1055.2569.3001.10083)新建数组并追加元素:
1. 使用Vue的数据绑定语法:
<template>
<button @click="addToArray">[添加](https://geek.csdn.net/educolumn/4d4bec229f163522438e69abc8681710?spm=1055.2569.3001.10083)元素</button>
<li v-[for](https://geek.csdn.net/educolumn/78c513cde50c58edec3efdd99a67bf21?spm=1055.2569.3001.10083)="item in myArray" :key="item">{{ item }}</li>
</template>
<script>
export default {
data() {
return {
myArray: []
methods: {
addToArray() {
this.myArray.push('新元素')
</script>
```