想通过设置动态style的方式设置设置animation属性,发现动态设置的animation动画没有经过Vue自己的编译(可能)
在class中定义的animation是有哈希的
直接通过style设置的animation是没有哈希的
解决方案一
删除scoped,不推荐,会污染全局
解决方案二
this.dymanicStyle = `@keyframes add-bezier {
from {transform: translateX(0px)}
to {transform: translateX(280px)}
}`
let sheet = document.styleSheets[0]
sheet.insertRule(this.dymanicStyle, 0)
在styleSheets中加入@keyframes
<div class="box" ref="box"></div>
this.$refs.box.style.animation = 'add-bezier 1s'
通过ref直接操作dom,将animation添加上去