Created
November 23, 2018 14:04
-
-
Save sandoche/b42bffeff0601e3330d82344a5367d8c to your computer and use it in GitHub Desktop.
Lessons Learned on Writing Apps with NativeScript VueJS - Example 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<Page @loaded="loaded($event)"> | |
<ActionBar :title="title" :flat="flat"/> | |
<StackLayout> | |
<PullToRefresh @refresh="refreshList"> | |
<ListView id="list" for="(news, index) in newsList" @itemTap="onItemTap" @loadMoreItems="updateList()" :items="newsList"> | |
<v-template> | |
<StackLayout> | |
<NewsItem :data="news"/> | |
<ActivityIndicator v-if="loading"/> | |
</StackLayout> | |
</v-template> | |
</ListView> | |
</PullToRefresh> | |
</StackLayout> | |
</Page> | |
</template> | |
<script> | |
// import of dependencies | |
// ... | |
export default { | |
name: 'App', | |
components: { | |
NewsItem, | |
NewsLoading | |
}, | |
data () { | |
return { | |
actionBarHidden: true, | |
flat: true, | |
title: 'GitNews' | |
} | |
}, | |
methods: { | |
...mapActions({ | |
retrieve: 'news/retrieve', | |
reset: 'news/reset' | |
}), | |
loaded (event) { | |
this.updateList() | |
}, | |
onItemTap (event) { | |
this.$navigateTo(Preview) | |
}, | |
updateList() { | |
this.checkNetwork() | |
this.retrieve() | |
}, | |
refreshList (args) { | |
this.checkNetwork() | |
this.reset() | |
this.retrieve() | |
}, | |
checkNetwork () { | |
if(getConnectionType() == connectionType.none) { | |
this.$navigateTo(NoNetwork) | |
} | |
} | |
}, | |
computed: mapGetters({ | |
loading: 'news/loading', | |
error: 'news/error', | |
newsList: 'news/list', | |
page: 'news/page', | |
after: 'news/after' | |
}) | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment