美文网首页
vue-resource 跨域的请求

vue-resource 跨域的请求

作者: xiaoaiai | 来源:发表于2017-08-02 10:01 被阅读0次
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="https://cdn.bootcss.com/vue/2.4.2/vue.min.js"></script>
        <script src="https://cdn.bootcss.com/vue-resource/1.3.4/vue-resource.min.js"></script>
    </head>
    <body>
        <div id="box">
            <button class="btn" @click="get()">btn</button>
            <ul v-for="item in mydata">
                <li>
                    {{item.text}}
                    ![](item.imgsrc)
                    {{item.right}}
                </li>
            </ul>
        </div>
        <script type="text/javascript">
            new Vue({
                el:'#box',
                data:{
                    dataurl:'http://www.xxxxx.com/ajax.php',  //请求的链接
                    mydata:[]
                },
                methods:{
                    get:function(){
                        this.$http.jsonp(this.dataurl,{
                            params:{
                                title:'abc' //请求时需要传入的参数(可选)
                            },
                            jsonp:'callback' //默认callback  (可根据需要修改)
                        }).then(function(res){
                            this.mydata = res.data
                        })
                    }
                }
            })
        </script>
    </body>
</html>

相关文章

网友评论

      本文标题:vue-resource 跨域的请求

      本文链接:https://www.haomeiwen.com/subject/itdelxtx.html