<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="vue.js"></script>
<script src="vue-resource.min.js"></script>
</head>
<body>
<div id="app"></div>
<script>
new Vue({
el:'#app',
data:{},
methods:{
getInfo() {
// 发起get请求
this.$http.get('地址').then(function(data){
// 成功回调*必须
// 获取成功后的返回数据
console.log(data.body);
})
},
postInfo() {
// 发起post数据
// 通过post方法第三个参数,{emulateJSON: true} 设置提交的内容类型为 普通表单
this.$http.post('地址','发送的数据对象{}',{emulateJSON: true}).then(function(){
// ...
})
},
jsonpInfo() {
// 发起jsonp 请求
this.$http.jsonp('地址').then(res => {
// ...
})
}
}
})
</script>
</body>
</html>
vue(六)vue-resource
最新推荐文章于 2024-01-22 15:55:53 发布