2015-10-20 19 views
9

vueJS ile oynuyor ve ajax isteğinden bazı verileri almayı deniyorum.

İşte benim kod:

new Vue({ 
el: '#recipeList', 

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

methods: { 
    fetchRecipes: function() { 
     this.$http.get('/recipes/ajax', function (recipes) { 

      this.$set('recipes') = recipes; 

     }); 
    } 
}}) 

html kodu iyidir, Bunu görmek gerekir şüpheliyim.

Bu belge ajax isteğinin nasıl yapıldığını belirtti, ancak $ http nesnesinin ayarlandığı görünmüyor.

TypeError: undefined is not an object (evaluating 'this.$http.get') 
fetchRecipesapp.js:10 
(anonymous function)vue.js:307 
readyapp.js:5 
_callHookvue.js:8197 
readyvue.js:10169 
$mountvue.js:10155 
_initvue.js:8054 
Vuevue.js:80 
global codeapp.js:1 
app.js:10 

cevap

18

$http.getVue Resource içindir: Burada

ben alıyorum konsol hatadır. Bunu düzgün bir şekilde çektiğinizden emin olun. yani
var Vue = require('vue'); 

Vue.use(require('vue-resource')); 

Ayrıca, kök yolunun düzgün bir şekilde kurulmuş olduğundan emin olun ... sonra npm sonra, yükleme için package.json için vue-resource ekleyin.

Vue.http.options.root = '/your-root-path'; 

Umut eder! :-)