Advertisement
Guest User

Untitled

a guest
Jul 7th, 2018
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <template>
  2.   <Page class="page">
  3.     <ActionBar class="action-bar" title="Posts"/>
  4.     <StackLayout>
  5.         <ListView for="post in posts" :loadMoreItems="proxPagina()">
  6.           <v-template>
  7.             <StackLayout backgroundColor="#3c495e">
  8.               <Label textWrap="true" :text="post.titulo" style="font-weight: bold; color: white; padding: 0 0 20"/>
  9.               <Label textWrap="true" :text="post.resumo" style="color: white"/>
  10.             </StackLayout>
  11.           </v-template>
  12.         </ListView>
  13.         <StackLayout>
  14.           <Label v-if="carregando" text="Carregando..." style="font-weight: bold; color: white; font-size: 15; text-transform: uppercase;" />
  15.         </StackLayout>
  16.     </StackLayout>
  17.   </Page>
  18. </template>
  19. <script>
  20. const httpModule = require("http");
  21. export default {
  22.   data: function() {
  23.       return {
  24.           posts: [], // Array to receive JSON response
  25.           carregando: true, // Sets to false when AJAX call is complete
  26.           pgNum: 1, // Will be used to display current page of posts loaded
  27.           httpPath: 'http://academiadoautismo.com.br/wp-json/wp/v2/posts?per_page=10&page=' // Base HTTP Path to request data
  28.       }
  29.   },
  30.   methods: {
  31.     proxPagina: function () {
  32.       if (!this.carregando) {
  33.         // Trying to stop it from firing before the ajax finishes loading;
  34.         // This works, but when the ajax finishes the event fires right away (twice), before scrolling;
  35.         // setTimeout was tested without success. The event fires twice after the timeout before scrolling;
  36.         alert("AEHOOOOOO");
  37.       }
  38.     },
  39.     loadItems: function (pageNum) {
  40.       let uri = this.httpPath+pageNum.toString();
  41.       this.pgNum = pageNum;
  42.       httpModule.getJSON(uri).then(response =>
  43.         {
  44.           this.posts = response.map(
  45.             post => {
  46.               return {
  47.                 id: post.id,
  48.                 titulo: post.title.rendered,
  49.                 data: post.date,
  50.                 resumo: post.excerpt.rendered.replace(/<\/?[^>]+(>|$)/g, ""),
  51.               }
  52.             }
  53.           );
  54.           this.carregando = false;
  55.         }
  56.       );
  57.     }
  58.   },
  59.   created: function () {
  60.     this.loadItems(1);
  61.     this.pgNum = 1;
  62.   },
  63. }
  64. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement