catspeake
2023-08-10 11:03:10
我對(duì) Vue.js 還很陌生,在讓庫(kù)正常工作時(shí)遇到了一些問(wèn)題,但沒(méi)有收到“錯(cuò)誤‘X’未定義 no-undef”消息。在這種情況下,未定義“Back”(它是 GSAP 的一部分),我認(rèn)為“定義”Back 的唯一位置是導(dǎo)入中。這只是導(dǎo)入庫(kù)的方法嗎?我是否必須像這樣編寫(xiě)導(dǎo)入中每個(gè)未定義的部分?它有效,但似乎沒(méi)有必要。<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>
1 回答

蝴蝶不菲
TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊
我不確定你從哪里學(xué)習(xí),但你使用的是 GSAP 的舊語(yǔ)法。如果您使用 GSAP 的新語(yǔ)法,則無(wú)需導(dǎo)入除gsap您的情況之外的任何內(nèi)容:
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')
? },
};
添加回答
舉報(bào)
0/150
提交
取消