Ajax 未设置此。$http vueJs
我正在玩vueJS,试图从ajax请求中获取一些数据 这是我的密码: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
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';
希望有帮助!:-)