2016-01-05 111 views
4

嗨我是Vue世界的新手,這裏是我得到的警告: 成功方法已被棄用。改用then方法。「成功」方法已被棄用。使用`then`方法

這裏是代碼:

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

而且這是做這樣的東西,一個正確的方法?

回答

6

你可以這樣做:

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

總而言之,vue-resource有些車和糙米。如果您使用最新版本,唯一的解釋是開發人員使用他自己的棄用方法。即,success而不是then

+0

這個作品,但後來我需要'v-for =「電影在movies.data' ins-v-for =」電影中的電影 – DokiCRO

+0

更新了我的答案。 –

+0

Thanks ... 20charts – DokiCRO

1

你的GET請求應該使用then承諾,像這樣:

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

要回答你的最後一個問題,你的方法沒有任何內在的錯誤。

+0

This works,but then I need to use'v-for =「movies in movies.data' insted of'v-for =」movie in movies「' – DokiCRO

+0

@ user3806764一旦你將電影設置爲你的數據屬性,您可以使用v-for指令列出電影中的所有影片。http://vuejs.org/guide/list.html。否則,您可以使用普通的JavaScript循環來循環播放影片。 –

相關問題