javascript - 为什么anime.js在vuejs中点击不起作用?
问题描述
现在,感谢mounted(),当页面更新时动画可以成功运行,但是由于某种原因,当你点击它时动画没有播放。
单击时会输出 console.log,但没有动画。我的错误是什么?
<template>
<div class="compHeader">
<h1 class="testVal" style="position: absolute;">QWERTY</h1>
<button type="button" class="testClick" @click="testClickGo().restart">+</button>
</div>
</template>
<script>
export default {
methods: {
testClickGo(){
console.log(111);
return this.$anime({
targets: '.testVal',
translateX: 200,
delay: 800
});
}
},
mounted(){
this.testClickGo();
}
}
</script>
解决方案
我找到了我的问题的答案。
<template>
<div class="compHeader">
<h1 ref="animeEl">hello, world!!</h1>
<button @click="anime.restart()">click me</button>
</div>
</template>
<script>
data: () => ({
anime: null,
}),
mounted() {
this.anime = this.$anime({
targets: this.$refs.animeEl,
translateX: 200,
delay: 800,
});
}
</script>
推荐阅读
- reactjs - 使用 Express.Router() 设置 Swagger UI
- c# - 使用 .NET Native 构建的 UWP 应用的象征性异常
- java - 使用 JVM Open J9 时应用程序(tomcat)在一段时间后停止响应
- c# - 用数据库中的数据填充组合框,然后从该组合框中用同一数据库中的另一个数据填充另一个组合框
- wordpress - 上传时发生错误。请稍后再试
- django - 如何将基于函数的视图更改为基于类的视图?
- sql - PostgreSQL 两个字段之间的百分比
- javascript - 如何在 react-flatpickr 中自动设置当前时间?
- excel - 查看excel中其他单元格的内容
- javascript - 调度函数的执行