Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Button text="Ciao" @tap="chiama" row="1" height="30" />
- </GridLayout>
- </Page>
- </template>
- <script >
- import { ObservableArray } from "@nativescript/core";
- const Api = require("./data/services.js");
- var link =
- "http://........................e";
- export default {
- data() {
- return {
- items: new ObservableArray(),
- };
- },
- async mounted() {..............},
- computed: {},
- },
- methods: {
- async chiama(){
- const chiamata = new Api();
- await chiamata.services(link);
- this.items = chiamata.getData();
- }
- },
- };
- </script>
- services.js
- class Api {
- constructor(url) {
- this.url = url;
- }
- items = [];
- async services(url) {
- try {
- const response = await fetch(url)
- const data = response.json()
- this.items.push(data)
- } catch (e) {
- console.log(e);
- }
- }
- getData() {
- console.log(this.items);
- return this.items;
- }
- }
- module.exports = Api;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement