javascript - 未捕获( promise )TypeError : undefined is not a function (Vue. js,Electron)

标签 javascript node.js vue.js promise electron

我正在尝试使用带有某些promise函数的anime.js动画一些元素,问题是,一旦前一个函数成功,第二个函数将无法运行。

<script>
import Splash from '../components/Splash.vue';
import Intro from '../components/Intro.vue';

export default {
  components: {
    Splash,
    Intro,
  },
  mounted() {
  //This is the line of the error `const animateSplash = async () => {` 
    const animateSplash = async () => {
      const splashAnim = this.$anime({
        targets: '.logo',
        easing: 'cubicBezier(.5, .05, .1, .3)',
        keyframes: [
          { duration: 1000, opacity: 0 },
          { duration: 1000, opacity: 1 },
          { delay: 3000, duration: 500, opacity: 0 },
        ],
        complete(anim) {
          document.querySelector('.logo-wrapper').style.display = 'none';
        },
      }).finished;

      await Promise.all(splashAnim);
    };

    animateSplash().then(() => {
      const introAnim = this.$anime({
        targets: '.intro-wrapper',
        easing: 'cubicBezier(.5, .05, .1, .3)',
        keyframes: [
          { duration: 1000, opacity: 0 },
          { duration: 1000, opacity: 1 },
        ],
        begin(anim) {
          document.querySelector('.intro-wrapper').style.display = 'flex';
        },
      }).finished;
    });
  },
};
</script>

我收到一个错误
Home.vue?76f2:17 Uncaught (in promise) TypeError: undefined is not a function再次指向const animateSplash = async () => {。但是它将运行第一个动画,即splashAnim

最佳答案

几点:

  • Promise.all()接受数组。 splashAnim似乎不是数组。 (已确认)
  • 如果splashAnim是Promise(甚至只是一个可忍受的话),则只需return splashAnim;即可。
  • 如果您正在处理Promises,则可以(并且应该争论)避免那些麻烦的begincomplete回调。

  • 据我所知(并假设this.$anime().finished确实返回Promise),您正在尝试执行以下操作:
    export default {
        components: { Splash, Intro },
        mounted() {
            return this.$anime({
                'targets': '.logo',
                'easing': 'cubicBezier(.5, .05, .1, .3)',
                'keyframes': [
                    { 'duration': 1000, 'opacity': 0 },
                    { 'duration': 1000, 'opacity': 1 },
                    { 'delay': 3000, 'duration': 500, 'opacity': 0 }
                ]
            }).finished
            .then(() => {
                document.querySelector('.logo-wrapper').style.display = 'none';
                document.querySelector('.intro-wrapper').style.display = 'flex';
                return this.$anime({
                    'targets': '.intro-wrapper',
                    'easing': 'cubicBezier(.5, .05, .1, .3)',
                    'keyframes': [
                        { 'duration': 1000, 'opacity': 0 },
                        { 'duration': 1000, 'opacity': 1 },
                    ]
                }).finished;
            });
        }
    };
    

    请注意,这两个return语句允许通过Promise将mounted()的调用者通知整个动画过程的完成。

    关于javascript - 未捕获( promise )TypeError : undefined is not a function (Vue. js,Electron),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62407481/

    相关文章:

    javascript - Angular 和 Vue 模板和绑定(bind)

    javascript - 使用 Vue.js 以更动态的方式显示复选框

    vue.js - 在导航选项卡上切换处于事件状态的 css 类

    javascript - 延迟 Ajax 提交

    javascript - 如何在 typescript 组件中调用 javascript 警报

    javascript - 使用 Node.js 读取上传到亚马逊 s3 存储桶的文件内容

    python - 我无法从 Express 应用程序执行 python 脚本

    node.js - 如何在 Bluemix 中向 Node 应用程序发出 cors 请求

    php - 自动完成以及文本字段的拼写检查和复数检查

    javascript - 无法从 jquery 选项卡小部件中删除 tabIndex