zoukankan      html  css  js  c++  java
  • vue-resource发送请求

    <!DOCTYPE html>
    <html>
    <head>
        <title>vue-resource</title>
        <meta charset="utf-8">
    </head>
    
    <body>
        <div id="app">
           <input type="button" value="get请求" @click="getInfo">
           <input type="button" value="post请求" @click="postInfo">
        </div>
    </body>
    <!-- 基于vue-resource实现get post请求 也可利用axios第三方包实现-->
    <script src="https://cdn.staticfile.org/vue/2.6.10/vue.js"></script>
    <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.js"></script>
    <script>
        // vue-promise是基于vue的,所以引入CDN库时需要注意顺序,应先引入vue
        let vm = new Vue({
            el: "#app",
            data:{
            },
            methods:{//vue-resource发送请求是基于promise的
                getInfo(){
                   this.$http.get('https://www.easy-mock.com/mock/5d537a1cf651bc6ff265fb77/example/result/cart.json') 
                    .then(res=>{
                        console.log(res);
                    })
                },
                postInfo(){
                    this.$http.post('https://www.easy-mock.com/mock/5d537a1cf651bc6ff265fb77/example/upload',{},{
                        emulateJSON:true//设置这个参数相当于application/x-www-form-urlencoded,由于手动提交请求没有默认表单格式,需要设置发送的数据格式
                    })
                    .then(res=>{
                        console.log(res.body);
                    })
                },
                }
        });
    </script>
    </html>
  • 相关阅读:
    BZOJ3282 Tree
    [NOI2004] 郁闷的出纳员
    [HNOI2004]宠物收养所
    [HNOI2002] 营业额统计
    图论 简单学习笔记
    POJ3321 Apple tree
    [国家集训队] 聪聪可可
    POJ2976 Dropping tests
    SCOI2005 最大子矩阵
    codeforces|CF13C Sequence
  • 原文地址:https://www.cnblogs.com/angle-xiu/p/11602272.html
Copyright © 2011-2022 走看看