查落补缺——.then()方法有什么作用?


问题

如题所示,源代码如下:

fetchCategory() {
      fetchCategory()
        .then((res) => {
          this.category = res.data;
        })
        .catch((err) => {
          console.log(err);
        });
    }

答案

vue的.then()方法

vue中的then方法

promise中的.then方法【待完善】

then()方法,异步执行,这里应该是将获取Mock的数据,然后赋值给category这个路由。