`success` 方法已被弃用.使用 `then` 方法代替 [英] The `success` method has been deprecated. Use the `then` method instead

查看:49
本文介绍了`success` 方法已被弃用.使用 `then` 方法代替的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Vue 世界的新手,这是我收到的警告:成功方法已被弃用.改用 then 方法.

Hi I am new to Vue world and here is the warning I get: The success method has been deprecated. Use the then method instead.

代码如下:

apiURL = 'api/movies';

new Vue({
   el: '#app',

   data: {
      'movies': ''
   },

   ready: function() {
      this.getMovies();
   },

   methods: {
      getMovies: function() {
         this.$http.get(apiURL, function(movies) {
            this.$set('movies', movies);
         });
      }
   }
});

这也是做这种事情的正确方法吗?

Also is this a right method to do this kind of stuff?

推荐答案

你可以这样做:

this.$http.get('/').then(function (response) {
    this.$set('movies', response.data);
}

总而言之,vue-resource 有一些缺陷和未完善.如果您使用最新版本,唯一的解释是开发人员使用了他自己的弃用方法.即,success 而不是 then.

All in all, vue-resource is somewhat buggy and unpolished. If you use the latest version, the only explanation would be that developer used his own deprecated method. Namely, success instead of then.

这篇关于`success` 方法已被弃用.使用 `then` 方法代替的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆