javascript - Vue.js。TypeError:即使确实安装了 vue-resource,也无法读取未定义的属性“帖子”
问题描述
可以,然后呢:
- 我得到一个 TypeError ,我不知道为什么,
- 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);
}
);
}```
解决方案
好的,所以我解决了。
问题是我不知道在哪里。我基本上不得不再次导入 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);
}
);
}
推荐阅读
- sql - Laravel Sql 软件
- java - 如何用 mybatis 映射 JSON_ARRAYAGG 结果
- java - 如何扩展java类中的所有变量
- git - 删除为多个存储库创建的单个 git 分支
- python-3.x - 在响应中将 lxml etree 作为 svg 发送
- c++ - 具有自定义范围 [0, 64] 的 C++ 数据类型?
- javascript - 将传单控制地理编码器与反应传单一起使用
- java - 为什么将 @Repository 放在 Spring Data JPA 接口之上?
- python - 如何使用 Python 为单元格填充颜色
- sql - 如何替换整数?