Skip to content

Commit 9a9d103

Browse files
committed
chore: add master-detail type of sample (WIP, crashes on iOS)
1 parent f09a33b commit 9a9d103

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

samples/app/app-with-page-routing.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
const Vue = require('./nativescript-vue')
2+
const VueRouter = require('vue-router')
3+
4+
Vue.config.silent = false
5+
Vue.config.debug = true
6+
7+
Vue.use(VueRouter)
8+
9+
const data = {
10+
items: [
11+
{
12+
id: 1,
13+
title: 'First Item',
14+
text: 'This is the first item, which is very shiny and fabulous.'
15+
},
16+
{
17+
id: 2,
18+
title: 'Second Item',
19+
text: 'This is the second item, which is also very shiny and fabulous.'
20+
},
21+
{
22+
id: 3,
23+
title: 'Third Item',
24+
text:
25+
'This is the third item, which has been added to this list just because.'
26+
}
27+
]
28+
}
29+
30+
const DetailPage = {
31+
data() {
32+
return {
33+
items: data.items
34+
}
35+
},
36+
computed: {
37+
current() {
38+
return this.items.find(item => item.id === +this.$route.params.id)
39+
}
40+
},
41+
template: `
42+
<Page>
43+
<ActionBar title="Detail Page">
44+
<NavigationButton text="Go Back" android.systemIcon="ic_menu_back" @tap="$router.back()" />
45+
</ActionBar>
46+
<StackLayout>
47+
<Label v-if="current" :text="current.text" textWrap="true" />
48+
49+
50+
<Label text="Related" />
51+
<Label text="Second Item" @tap="$router.replace('/detail/2')" style="color: blue; text-decoration: underline;" />
52+
</StackLayout>
53+
</Page>
54+
`
55+
}
56+
const MasterPage = {
57+
data() {
58+
return {
59+
items: data.items
60+
}
61+
},
62+
template: `
63+
<Page>
64+
<ActionBar title="MasterPage" />
65+
<GridLayout>
66+
<ListView for="item in items" @itemTap="onItemTap" separatorColor="transparent">
67+
<v-template>
68+
<GridLayout style="border-bottom-width: 2; border-bottom-color: red;">
69+
<Label :text="item.title" style="padding: 20"/>
70+
</GridLayout>
71+
</v-template>
72+
</ListView>
73+
</GridLayout>
74+
</Page>
75+
`,
76+
77+
methods: {
78+
onItemTap({ item }) {
79+
this.$router.push(`/detail/${item.id}`)
80+
}
81+
}
82+
}
83+
84+
const router = new VueRouter({
85+
pageRouting: true,
86+
routes: [
87+
{ path: '/', component: MasterPage },
88+
{ path: '/detail/:id', component: DetailPage },
89+
{ path: '*', redirect: '/' }
90+
]
91+
})
92+
93+
router.replace('/')
94+
95+
new Vue({
96+
router
97+
}).$start()

0 commit comments

Comments
 (0)