相关疑难解决方法(0)

这个.$ http vueJs未设置

我正在玩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)

ajax

13
推荐指数
1
解决办法
1万
查看次数

VueJS http获取请求

尝试使用Vue js发送http get请求。看不到逻辑上的任何问题,但是使用vuejs经验不足。

继续出现以下两个错误:

[Vue警告]:挂接的钩子中出现错误:“ TypeError:无法读取未定义的属性'get'

TypeError:无法读取未定义的属性“ get”。

var owm = new Vue({
  el: '#owm',
  data: {
    debug: true,
    weather: []
  },
  methods: {
    loadWeather: function() {
      this.$http.get('http://api.openweathermap.org/data/2.5/find?q=stockholm&type=like&appid=766b78c39446a8fa6313c3b7b2063ade', function(data, status, request){
        if(status == 200)
        {
          this.weather = data;
          console.log(this.weather);
        }
      });
    }
  },
  mounted: function () {
    this.loadWeather();
  }
});
Run Code Online (Sandbox Code Playgroud)

使用vue资源更新了代码,错误已消失,但不会控制台记录任何数据,这可能是什么问题?

Vue.use(VueResource);
var owm = new Vue({
  el: '#owm',
  data: {
    weather: []
  },
  methods: {
    loadWeather: function() {
      this.$http.get('http://api.openweathermap.org/data/2.5/find?q=stockholm&type=like&appid=[API KEY]', function(data, status, request){
        if(status == 200)
        {
          this.weather …
Run Code Online (Sandbox Code Playgroud)

javascript http vue.js

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

ajax ×1

http ×1

javascript ×1

vue.js ×1