vue使用resource传参数
html>html lang="en">head>meta charset="UTF-8">title>交互title>script src="https://unpkg.com/vue">script>script src="vue-resource.js">script>head>body>div id="app">
·
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>交互</title> <script src="https://unpkg.com/vue"></script> <script src="vue-resource.js"></script> <!-- ajax(数据交互接口) --> </head> <body> <div id="app"> <input type="submit" value="确定获取数据" @click="getadd()"> </div> </body> </html> <script> var app = new Vue({ el:'#app', data: {}, methods: { getadd: function() { // post 传参数 需要加 {emulateJSON:true} this.$http.post('in.php',{a:1,b:2},{emulateJSON:true}).then( (res) => { console.log(res.data) } ) // get传参数 需要 {params: {你传的值}} this.$http.get('getin.php',{params: {a:1,b:2}}).then( (res) => { console.log(res.data) }) // jsonp 传参数 this.$http.jsonp("https://sug.so.360.cn/suggest",{params:{word:'a'}}).then( (res)=>{ console.log(res.data.s) }) } } }) </script> in.php<?php $a = $_GET['a']; $b = $_GET['b']; echo $a.'---'.$b; ?>
更多推荐
已为社区贡献20条内容
所有评论(0)