Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vue.js

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.

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

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

like image 200
DokiCRO Avatar asked Mar 14 '23 17:03

DokiCRO


2 Answers

You can do:

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

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.

like image 168
Yauheni Prakopchyk Avatar answered Mar 16 '23 07:03

Yauheni Prakopchyk


Your GET request should be using the then promise like so:

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

Just as shown in the vue-resource read-me page: https://github.com/vuejs/vue-resource#example

The deprecation warning is coming from this line: https://github.com/vuejs/vue-resource/blob/ed85a38a1c88faf4e1ac1d7c15cca8376aa933c8/dist/vue-resource.js#L853

To answer your last question, there is nothing inherently wrong with your methods.

like image 28
Amir Rustamzadeh Avatar answered Mar 16 '23 05:03

Amir Rustamzadeh