爬过得那些坑
前言:在整个Vue的过程中,遇到了不少坑。查找不同的资料,把这些坑给填了,记录下这些坑,以及解决办法。
一、Http请求的那些坑
1.不支持http请求
表现为:程序启动正常,点击按妞不跳转,后台无响应,浏览器调试出现
Uncaught TypeError: Cannot read property 'post' of undefined
解决办法:添加vue-resource支持,在main.js添加
import VueResource from 'vue-resource'
Vue.use(VueResource);
2.post请求,后台接收参数为null
表现为:后台响应但是参数为null,正确的登陆失效,调试时,参数为from object
解决办法:http请求中,添加
{emulateJSON:true}
全部的Http请求部分代码为
_this.$http.post('http://localhost:8080/person/login', {
username: _this.username