[英]How to trigger a click on dynamic element in Vue.js?
I have dynamically generated tabs with a range of time(from 8am - 9am).我已经动态生成了具有一定时间范围的标签(从上午 8 点到上午 9 点)。 I'm trying to trigger a click when the current time is in between the range.
当当前时间在范围之间时,我试图触发点击。 I added the
ref
but getting it unidentified
.我添加了
ref
但得到它unidentified
。
<li v-for="(chore, index) in chores" :key="chore.id">
<a :ref="chore.time_from +'-'+ chore.time_to">Link</a>
</li>
and the script和脚本
created() {
const me = this;
this.axios.get(`api/chores/${this.$route.name}`).then(response => {
this.chores = _.orderBy(response.data, "time_from", "asc");
$.each(response.data, function(key, value) {
if (value.time_from < me.getNow() && value.time_to > me.getNow()) {
const i = value.time_from + "-" + value.time_to;
const a = me.$refs.i; // **unidentified**
console.log(a);
a.click();
}
});
});
},
what I ended up doing is to push the response to the finally()
function我最终做的是将响应推送到
finally()
function
ref="chores"
and和
.then(response => {
this.chores = _.orderBy(response.data, "time_from", "asc");
$.each(response.data, function(key, value) {
if (value.time_from < me.getNow() && value.time_to > me.getNow()) {
i.push(key);
}
});
})
.finally(() => this.$refs.chores[i].click());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.