TypeError:使用Vue.js时无法读取未定义的属性'then'

问题描述 投票:0回答:2

我在Vue.js组件中运行了一些代码,但是出现以下错误:

TypeError:无法读取未定义的属性'then'

我只想在文件读取之前运行loadingAnimation(),但是在Internet上搜索此错误并没有真正帮助我。最好的方法是什么?

这是我的代码:

openFileBrowse() {
      var vm = this;
      var input = document.getElementById("filebutton");
      if (input.files[0].type != "application/vnd.ms-excel"){
      alert("You have uploaded a wrong file type. We require a .csv file not a " + input.files[0].type + " file.");
      } else {
        //Update loader text
        vm.updateLoader('parsing csv');

        //Start loadscreen
        vm.loadingAnimation().then(function () {
          //Start reading data
          var reader = new FileReader();
          var csvData = "";
          var jsonData;
          var iconv = require('iconv-lite');
          reader.onload = function(){
            csvData = iconv.decode(reader.result, 'latin1');
            jsonData = vm.tsvJSON(csvData);
            vm.addFiles(jsonData);
          };
          reader.onloadend = function(){
            //Go to visualization page
            router.push({ name: 'Visualization' });
          };
        reader.readAsText(input.files[0]);
        });
      }
    },
    loadingAnimation() {
      //Make loading screen visible with animation
      var target = document.getElementById('loadBox');
      target.classList.remove('hidden')
      setTimeout(function () {
      target.classList.remove('visuallyhidden');
      }, 20);
    }
javascript vue.js asynchronous
2个回答
1
投票

loadingAnimation不是async函数,并且不会显式返回诺言,因此调用它不会给您诺言。实际上,它没有any

© www.soinside.com 2019 - 2024. All rights reserved.