千峰商城-springboot项目搭建-40-axios介绍及入门使用

1.axios:vue可以实现数据的渲染,但是如何获取数据?

vue本身不具备通信能力,通常结合axios——一个专注于异步通信的js框架来使用。

axios负责数据通信,vue负责数据渲染。

 

 

2.axios入门使用:

原生ajax:实现步骤复杂。

jQuery:笨重。

axios:专注于异步通信。简洁、高效、对RESTful支持良好。

 

 

axios官方文档:http://www.axios-js.com/

cdn:
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

 

 

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script type="text/javascript" src="js/vue.js" ></script>
        <script type="text/javascript" src="js/axios.min.js" ></script>
        
    </head>
    <body>
        <div id="container">
            <button type="button" @click="test1">测试1</button>
        </div>
        <script type="text/javascript">
            var vm = new Vue({
                el:"#container",
                methods:{
                    test1:function(){
                        //发送异步请求
                        //axios.get(url).then(function);
                        //axios.get(url,{}).thrn(function);
                        axios.get("http://localhost:9999/music/detail",{params:{id:"28059417"}}).then(function(res){
                            console.log(res);
                        });
                        
                    }
                }
            });
        </script>
    </body>
</html>

 

 
 
posted @ 2022-07-11 18:22  临易  阅读(71)  评论(0编辑  收藏  举报