我正在玩vueJS并尝试从ajax请求中获取一些数据.
继承我的代码:
new Vue({
el: '#recipeList',
ready: function () {
this.fetchRecipes();
},
methods: {
fetchRecipes: function () {
this.$http.get('/recipes/ajax', function (recipes) {
this.$set('recipes') = recipes;
});
}
}})
Run Code Online (Sandbox Code Playgroud)
HTML代码很好,我怀疑你需要看到它.
文档说这是你执行ajax请求的方式,但$ http对象似乎没有设置.
这是我收到的控制台错误:
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
Run Code Online (Sandbox Code Playgroud)
Don*_*aJo 23
$http.get
适用于Vue资源.确保你正确地拉动它.即,添加vue-resource
到您的package.json,然后npm安装,然后...
var Vue = require('vue');
Vue.use(require('vue-resource'));
Run Code Online (Sandbox Code Playgroud)
另外,请确保正确设置了根路径.
Vue.http.options.root = '/your-root-path';
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你!:-)
归档时间: |
|
查看次数: |
13852 次 |
最近记录: |