vue使用resource传参数

<!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>
--------------------- 
作者:echo_Ae 
来源:CSDN 
原文:https://blog.csdn.net/echo_ae/article/details/77863113?utm_source=copy 
版权声明:本文为博主原创文章,转载请附上博文链接!

 

posted @ 2018-10-11 16:29  浮尘微光  阅读(3641)  评论(0)    收藏  举报