Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div id="discordAPP">
- <ul style="list-style:none" v-for="user in posts" :key="user.index">
- <li>
- {{user.name}}
- </li>
- </ul>
- </div>
- <script>
- new Vue({
- el:'#discordAPP',
- data: {
- posts: [],
- timer: "",
- },
- created() {
- this.fetchData();
- this.timer = setInterval(this.fetchData, 5000);
- },
- methods: {
- async fetchData() {
- const res = await fetch("https://discord.com/api/guilds/725425138442698822/widget.json");
- const data = await res.json();
- this.posts = data;
- },
- cancelAutoUpdate() {
- clearInterval(this.timer);
- },
- },
- beforeDestroy() {
- this.cancelAutoUpdate();
- },
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment