Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax 未设置此。$http vueJs_Ajax - Fatal编程技术网

Ajax 未设置此。$http vueJs

Ajax 未设置此。$http vueJs,ajax,Ajax,我正在玩vueJS,试图从ajax请求中获取一些数据 这是我的密码: new Vue({ el: '#recipeList', ready: function () { this.fetchRecipes(); }, methods: { fetchRecipes: function () { this.$http.get('/recipes/ajax', function (recipes) { this.$set('recipes

我正在玩vueJS,试图从ajax请求中获取一些数据

这是我的密码:

new Vue({
el: '#recipeList',

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

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

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

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

$http.get
用于。确保正确地将其拉入。i、 例如,将
vue资源
添加到package.json,然后安装npm,然后

var Vue = require('vue');

Vue.use(require('vue-resource'));
此外,请确保根路径设置正确

Vue.http.options.root = '/your-root-path';
希望有帮助!:-)