<template>
<div>
敌军还有
<span class="mouse" @click="add">{{time.you}}</span>
秒钟到达战场,受到敌方钟无艳攻击
<span class="mouse" @click="reduce">{{time.me}}</span>
次
<div v-for="item in heros" :key="item.id">{{item.hero}}</div>
<el-button type="success" @click="edit">修改英雄</el-button>
<el-button type="success" @click="addHero">添加英雄</el-button>
</div>
</template>
<script>
export default {
data() {
return {
time: {},
heros: [
{ hero: "李白", id: "0" },
{ hero: "甄姬", id: "1" },
{ hero: "典韦", id: "2" },
{ hero: "李元芳", id: "3" },
{ hero: "吕布", id: "4" }
]
};
},
created() {
this.time = { you: 10 };
// this.time.me = 0;无效的
this.$set(this.time, "me", 10);
},
methods: {
add() {
this.time.you++;
},
reduce() {
if (this.time.me-- === 0) this.time.me = 10;
},
edit() {
this.$set(this.heros, 0, { hero: "鱼", id: "0" });//修改索引为0的英雄
},
addHero() {
this.$set(this.heros, this.heros.length, {
hero: "猴子",
id: this.heros.length
});
}
}
};
</script>