Advertisement
pirriaf

Untitled

Feb 2nd, 2022
1,284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <Button text="Ciao" @tap="chiama" row="1" height="30" />
  2.     </GridLayout>
  3.   </Page>
  4. </template>
  5.  
  6. <script >
  7. import { ObservableArray } from "@nativescript/core";
  8. const Api = require("./data/services.js");
  9.  
  10. var link =
  11.   "http://........................e";
  12.  
  13. export default {
  14.   data() {
  15.     return {
  16.       items: new ObservableArray(),
  17.     };
  18.   },
  19.   async mounted() {..............},
  20.  
  21.   computed: {},
  22.   },
  23.   methods: {
  24.     async chiama(){
  25.       const chiamata = new Api();
  26.       await chiamata.services(link);
  27.       this.items = chiamata.getData();
  28.     }
  29.   },
  30. };
  31. </script>
  32.  
  33.  
  34. services.js
  35.  
  36. class Api {
  37.     constructor(url) {
  38.         this.url = url;
  39.     }
  40.  
  41.  
  42.     items = [];
  43.  
  44.     async services(url) {
  45.         try {
  46.             const response = await fetch(url)
  47.             const data = response.json()
  48.             this.items.push(data)
  49.         } catch (e) {
  50.             console.log(e);
  51.         }
  52.     }
  53.  
  54.  
  55.     getData() {
  56.         console.log(this.items);
  57.         return this.items;
  58.     }
  59.  
  60. }
  61.  
  62.  
  63. module.exports = Api;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement