vue $http请求服务
来源:互联网 发布:笔记本支架哪个好 知乎 编辑:程序博客网 时间:2024/06/05 04:06
vue中的$http服务 需要引入一个叫vue-resource.js的文件,因为vue.js中没有$http服务。如果需要使用这个服务去百度下载vue-resource.js
第一种get方法
<!DOCTYPE html><html><head><meta charset="UTF-8"><title></title><script src="js/vue.js"></script><script src="js/vue-resource.js"></script></head><body><div id="app"><input type="button" value="点击获取" @click="get()"/></div><script>new Vue({el:"#app",methods:{get:function(){this.$http.get('get.php',{a:10,b:1}).then(function(res){alert(res.data);},function(res){alert(res.status)});}}})</script></body></html>
get.php文件:
<?php
$a=$_GET['a'];
$b=$_GET['b'];
echo $a-$b;
?>
get方法有两个参数get("PHP文件",“参数”)
post方法:
<!DOCTYPE html><html><head><meta charset="UTF-8"><title></title><script src="js/vue.js"></script><script src="js/vue-resource.js"></script></head><body><div id="app"><input type="button" value="点击获取" @click="get()"/></div><script>new Vue({el:"#app",methods:{get:function(){this.$http.post('post.php',{a:2,b:3},{emulateJSON:true}).then(function(res){alert(res.data);},function(res){alert(res.status)});}}})</script></body></html>post.php:
<?php
$a=$_POST['a'];
$b=$_POST['b'];
echo $a+$b;
?>
post方法有三个参数post("php文件","参数","emulateJSON:true")
emulateJSON:true 模拟一个JSON数据发送到服务器,这样才可以成功运行
这样放在服务器环境下就可以运行了,我用的是phpstudy
阅读全文
0 0
- vue $http请求服务
- Vue axios处理http请求
- Vue axios处理http请求
- 使用Vue构建Ionic混合APP系列教程(三):服务和Http请求
- 通过http请求服务
- http请求服务
- AngularJs $http 请求服务
- AngularJs服务-http请求
- AngularJs $http 请求服务
- AngularJs $http 请求服务
- 【03】vue.js — http请求交互
- Vue-cli之http请求代理
- vue vue-cli请求后台服务地址要注意点
- http发送服务请求实例
- AngularJs $http 请求服务整理
- Java http请求调用服务
- 发送http post请求soap服务
- 发送http post请求soap服务
- 442. Find All Duplicates in an Array[Medium]
- openstack中VM迁移
- iOS多线程GCD简单用法
- 15 个常用的 JavaScript 正则表达式
- Numpy 索引
- vue $http请求服务
- ListView Columns Name屬性為空
- extjs正则表达式验证
- 10大计算机经典算法
- ControllerShutdownRequest分析
- App的启动过程(2)framework侧-恢复最上层的Activity
- Logistic逻辑回归模型(LR)基础
- Mac 以及移动端 抓包神器 Charles 的使用详解
- 可放大缩小的ImageView