[英]How to trigger a click on dynamic element in Vue.js?
我已经动态生成了具有一定时间范围的标签(从上午 8 点到上午 9 点)。 当当前时间在范围之间时,我试图触发点击。 我添加了ref
但得到它unidentified
。
<li v-for="(chore, index) in chores" :key="chore.id">
<a :ref="chore.time_from +'-'+ chore.time_to">Link</a>
</li>
和脚本
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();
}
});
});
},
我最终做的是将响应推送到finally()
function
ref="chores"
和
.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.