vue+axios点击事件请求后端接口超级简单实例代码
代码比较简单,具有基本的逻辑处理,需要的可以根据业务扩展
代码如下
<!DOCTYPE html> <html> <head> <title>vue+axios点击事件请求后端接口</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> </head> <body> <div class="pannel-3" id="app"> <button class="box" @click="follow_click(357,356)"><span>+</span>关注</button> </div> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script> <script type="text/javascript"> var vm = new Vue({ el: '#app', data: { who_follow: 0, //关注人uid follow_who: 0, //被关注人uid }, methods: { follow_click:function (who_follow,follow_who) { axios({ method: 'post', url: 'http://www.dsc2.com/people.php', data: { who_follow: vm.who_follow, follow_who: vm.follow_who } }) .then(function (response) { console.log(JSON.stringify(response)); }) .catch(function (error) { console.log(error); }); }, } }); </script> </body> </html>