首页 > 其他 > 详细

05.vue-resource的基本使用

时间:2019-08-03 17:16:24      阅读:44      评论:0      收藏:0      [点我收藏+]

<!DOCTYPE html>
<html lang="en">

<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.js"></script>
    <!-- 注意:vue-resource依赖于vue,所以在引用时要注意顺序 -->
    <!-- this.$http -->
    <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>

</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>
</body>
<script>
    new Vue({
        el: #app,
        data: {

        },
        methods: {
            getInfo() {
                //通过.then来是指成功的回调函数
                this.$http.get(https://cn.vuejs.org).then(function(result) {
                    //通过result.body拿到服务器返回成功的数据
                    //console.log(result.body);
                })
            },
            postInfo() { //发起post请求
                //手动发起的post请求,默认没有表单格式,所以有的服务器处理不了
                //通过post方法的第三个参数,设置提交内容的类型为普通表单数据格式
                this.$http.post(http://vue-studyit.io/api/post, {}, {
                    emulateJSON: true
                }).then(function(result) {
                    //console.log(result.body)
                })
            },
            jsonpInfo() { //发起jsonp 请求
                this.$http.jsonp(http://vue-studyit.io/api/jsonp).then(result => {
                    console.log(result.body)
                })
            }
        }
    })
</script>

</html>

 

05.vue-resource的基本使用

原文:https://www.cnblogs.com/LittleDuan/p/11295425.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!