• vue-2.5-vue-resource的使用-get、post、jsonp发送请求


    <!DOCTYPE html>
    <html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml">
    <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="../lib/vue.min.js"></script>
        <link rel="stylesheet" href="../lib/bootstrap.min.css">
    </head>
    <body>
    <div id="app">
        <input type="button" value="get请求" @click="getInfo">
        <input type="button" value="post请求" @click="postInfo">
        <input type="button" value="jsonp请求" @click="jsonpInfo">
    </div>
    <script>
        // 创建 Vue 实例,得到 ViewModel
        var vm = new Vue({
            el: '#app',
            data: {
            },
            methods: {
                getInfo() { // 发起 get请求
                    // 当发起get请求之后,通过 .then 来设置成功的回调函数
                    this.$http.get('http://vue.studyit.io/api/getlunbo').then(function (result) {
                        console.log(result)
                    })
                },
                postInfo() { // 发起 post请求
                    // 当发起get请求之后,通过 .then 来设置成功的回调函数
                    this.$http.post('http://vue.studyit.io/api/post',{},{}).then(function (result) {
                        console.log(result)
                    })
                },
                getInfo() { // 发起 jsonp请求
                    // 当发起get请求之后,通过 .then 来设置成功的回调函数
                    this.$http.jsonp('http://vue.studyit.io/api/jsnop').then(result=> {
                        console.log(result.body)
                    })
                }
            },
        })
    </script>
    </body>
    </html>
  • 相关阅读:
    阿里云磁盘扩容
    【Vue】WebPack 忽略指定文件或目录
    MySQL 全文索引 (FullText)
    产品设计
    13-Java面向对象-抽象类与接口
    06-数据存储
    07-网络与通信-02-Android中基于HTTP的通信技术
    10-Android 广播接收器 BroadcastReceiver
    09-Android 中 AIDL 的理解与使用
    09-Android 中 AIDL 的理解与使用
  • 原文地址:https://www.cnblogs.com/cgy-home/p/11326665.html
Copyright © 2020-2023  润新知