Vue-07-vue resource 使用简介
2017年9月4日小于 1 分钟
使用方式
Document
var vm = new Vue({ // 创建新的 vue 实例
el = "#app", // 获取id
data = {}, // 数据对象
// 发起请求
getInfo () { // 发起 get 请求
this.$http.get(url, {params: {JSONdata} }.then(function(result){
console.log(result)
console.log(result.body)// 通过 result.body 拿到服务器返回内容
}))
},
postInfo () {
// 第一个是地址,第二个是提交数据,第三个是格式 为普通表单
this.$http.post('url', {}, {emulateJSON: true}).then(
result=>{
console.log(result.body)
}
)
},
})
emulateJSON 配置
emulateJSON: true 将请求认为是表单
如果你想传输 json 到后台,将这个值设置为 false 即可。
拓展阅读
参考资料
贡献者
binbin.hou