thommy1972de

Untitled

Jul 18th, 2021
1,423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. <div id="discordAPP">
  2.     <ul style="list-style:none" v-for="user in posts" :key="user.index">
  3.         <li>
  4.             {{user.name}}
  5.         </li>
  6.     </ul>
  7. </div>
  8.  
  9. <script>
  10. new Vue({
  11.     el:'#discordAPP',
  12.     data: {
  13.       posts: [],
  14.       timer: "",
  15.     },
  16.     created() {
  17.     this.fetchData();  
  18.     this.timer = setInterval(this.fetchData, 5000);
  19.     },  
  20.     methods: {  
  21.       async fetchData() {  
  22.         const res = await fetch("https://discord.com/api/guilds/725425138442698822/widget.json");  
  23.         const data = await res.json();  
  24.         this.posts = data;  
  25.       },
  26.       cancelAutoUpdate() {  
  27.         clearInterval(this.timer);  
  28.       },  
  29.     },
  30.     beforeDestroy() {  
  31.       this.cancelAutoUpdate();  
  32.     },  
  33.   });
  34. </script>
Advertisement
Add Comment
Please, Sign In to add comment