参考代码:
<!DOCTYPE html> <html> <head> <Meta charset="utf-8" /> <title>Vue的Ajax、数组、动画等技术综合测试-B</title> <style> .v-enter, .v-leave-to { opacity: 0; transform: translateY(80px); } .v-enter-active, .v-leave-active { transition: all 0.6s ease; } </style> </head> <body> <div id="app"> <input type="button" value="按照ID" @click="ZdySIDSort()" /> <input type="button" value="按照Name" @click="ZdyNameSort()" /> <transition-group appear tag="ul"> <li v-for="i,index in list" :key="i.PlayerSID" @click="del(i.PlayerSID)"> {{index}}-{{i.PlayerSID}}-{{i.PlayerName}} </li> </transition-group> </div> <script src="../js/vue.js"></script> <script src="../node_modules/axios/dist/axios.min.js"></script> <script> new Vue({ el: "#app", data: { list: null, sortoption: true, }, methods: { ZdySIDSort() { if (this.sortoption == true) { this.list.sort((a, b) => a.PlayerSID - b.PlayerSID); } else { this.list.sort((a, b) => b.PlayerSID - a.PlayerSID); } this.sortoption = !this.sortoption; }, ZdyNameSort() { this.list.sort((c, d) => { if (this.sortoption == true) { var x = c.PlayerName; var y = d.PlayerName; return x < y ? -1 : x > y ? 1 : 0; } else { var y = c.PlayerName; var x = d.PlayerName; return x < y ? -1 : x > y ? 1 : 0; } }); this.sortoption = !this.sortoption; }, del(id) { var index = this.list.findindex((item) => { if (item.PlayerSID == id) { return true; } }); this.list.splice(index, 1); }, }, mounted() { let self = this; axios.get("http://www.dshow.net:8038/api/rankdshow/11") .then(function (response) { self.list = response.data; }) .catch(function (error) { // 请求失败处理 console.log(error); }); }, }); </script> </body> </html>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。