简体   繁体   English

这是在 vue.js 中导入 gsap 的正确方法(它有效,但它是“正确”的方法吗?)

[英]Is this the right way to import gsap in vue.js (it works but is it the "right" way?)

I'm quite new to Vue.js and have had some problems getting libraries to work without getting the "error 'X' is not defined no-undef" message.我对 Vue.js 很陌生,并且在让库正常工作而没有收到“错误 'X' is not defined no-undef”消息时遇到了一些问题。

In this case it is 'Back' that is not defined (which is a part of GSAP) I figured the only place to "define" Back would be in the import.在这种情况下,未定义“返回”(这是 GSAP 的一部分)我认为“定义”返回的唯一位置将在导入中。

Is this just the way to import libraries?这只是导入库的方式吗? Do I have to write every undefined part in the import like this?我是否必须像这样在导入中编写每个未定义的部分? It works but it just seems unnecessary.它有效,但似乎没有必要。

 <template> <div id="mainTemplate"> <h2>This is the MainTemplaye.vue Component</h2> <div ref="box" class="box"></div> </div> </template> <script> import { TimelineLite, Back } from "gsap"; export default { name: "MainTemplate", mounted() { const { box } = this.$refs; const timeline = new TimelineLite(); timeline.to(box, 1, { x: 200, rotation: 90, ease: Back.easeInOut, }) timeline.to(box, 0.5, { background: 'green' },'-=0.5') }, }; </script> <style> .box { height: 60px; width: 60px; background: red; } </style>

I'm not sure where you're learning from, but you're using the old syntax of GSAP.我不确定您从哪里学习,但您使用的是 GSAP 的旧语法。 If you use the new syntax of GSAP you don't have to import anything other than gsap in your case:如果您使用 GSAP 的新语法, gsap在您的情况下,您不必导入gsap以外的任何内容:

import { gsap } from "gsap";

export default {
  name: "MainTemplate",
  mounted() {
    const { box } = this.$refs;
    const timeline = gsap.timeline();

    timeline.to(box, { duration: 1, x: 200, rotation: 90, ease: 'back.inOut' })
    timeline.to(box, { background: 'green' }, '-=0.5')
  },
};

The best place to start learning is the official GSAP Getting Started article .开始学习的最佳位置是官方 GSAP 入门文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM