首页 > 解决方案 > Vue.js。TypeError:即使确实安装了 vue-resource,也无法读取未定义的属性“帖子”

问题描述

可以,然后呢:

  1. 我得到一个 TypeError ,我不知道为什么,
  2. Vue-resource 已安装,并导入Vue.use('vue-resource'); import {} from 'vue-resource';到我的 main.js 中。

我尝试过以不同的方式导入它,我一直在寻找解决方案,但没有运气。

我调用该函数的地方是在我单击按钮之后 <button class="btn btn-primary" @click="submit()">Submit</button>

“提交”函数如下所示:


      this.$http
        .post("https://vue-http-20bf2.firebaseio.com/data.json", this.user)
        .then(
          response => {
            console.log(response);
          },
          error => {
            console.log(error);
          }
        );
    }```

标签: javascriptvue.jsvuejs2vue-resource

解决方案


好的,所以我解决了。

问题是我不知道在哪里。我基本上不得不再次导入 Vue 和 VueResource,并告诉 Vue 使用该包(再次)。

import Vue from 'vue'
import VueResource from 'vue-resource';
import App from './App.vue'

`Vue.use(VueResource);`

请注意,我已经尝试过这样做。

在 App.vue 中,我有

submit() {
      this.$http
        .post("https://vue-http-20bf2.firebaseio.com/data.json", this.user)
        .then(
          response => {
            console.log(response);
          },
          error => {
            console.log(error);
          }
        );
    }

推荐阅读