【发布时间】:2018-10-16 21:07:46
【问题描述】:
请告诉我我做错了什么?我想每 2 秒激活一次“布料”更新。还在学习vue。谢谢
data() {
return {
clothes: ['t-shirts', 'sneakers', 'jackets'],
count: 0,
cloth: ''
}
},
methods: {
startInterval() {
setInterval(() => {
this.cloth = this.clothes[this.count]
this.count++
if (this.count >= this.clothes.length) {
this.count = 0;
}
}, 2000)
}
}
【问题讨论】:
-
你在哪里执行
startInterval? -
哦..没错..如果我使用 startInterval 添加事件点击,它就可以工作。但是如何让这个函数自动运行呢?
标签: vue.js vuejs2 setinterval