The success method has been deprecated. Use the `then` method instead

Hi, I am new to Vue, and here is the warning I get: Success method is deprecated. Use the then method instead.

And here is the code:

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);
         });
      }
   }
});

Is this also the right method for this kind of thing?

+4
source share
2 answers

You can do:

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

In general, vue-resourcesomewhat defective and unpolished. If you are using the latest version, the only explanation would be that the developer used his own deprecated method. Namely, successinstead then.

+6
source

Your GET request should use the promise thenlike this:

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

vue-: https://github.com/vuejs/vue-resource#example

: https://github.com/vuejs/vue-resource/blob/ed85a38a1c88faf4e1ac1d7c15cca8376aa933c8/dist/vue-resource.js#L853

, .

+1

Source: https://habr.com/ru/post/1622888/


All Articles