Telerik DevRel
Developer Relations team @ Telerik!
Jen Looper
Senior Developer Advocate, Progress
@jenlooper
Tiago Alves
Igor Randjelovic
Lol I need a code sharing talk STAT
Lol ok, have fun!
https://github.com/vuejs/vue/pull/7264
https://github.com/nativescript-vue/nativescript-vue-webpack-template
<template web>
<div class="SealGallery">
<ul style="padding: 0;">
<li v-for="seal in seals" :key="seal.id"
style="list-style: none; border-bottom: 1px solid #e0e0e0;">
<div style="display: flex; align-items: center; padding: 10px">
{{ seal.name }}
</div>
</li>
</ul>
</div>
</template>
<template native>
<StackLayout>
<ListView :items="seals">
<v-template>
<StackLayout orientation="horizontal">
<Label :text="item.name" style="vertical-align: center;padding: 10px;"/>
</StackLayout>
</v-template>
</ListView>
</StackLayout>
</template>
NativeScript-Vue-Loader picks out the pieces to compile
https://github.com/tralves/ns-vue-codeshare-demo
SFCs go here, with naming convention set
Entry points
Shared service
Global styles
<template>
<Page class="Page">
<ActionBar title="🐕🐩🐕🐩🐕🐩🐕🐩🐕🐩🐕🐩🐕🐩" class="action-bar" />
<ScrollView>
<WrapLayout orientation="horizontal">
<StackLayout v-for="dog in dogsList" :key="dog" class="card">
<Image height="100%" width="48%" stretch="aspectFill" :src="dog" />
</StackLayout>
</WrapLayout>
</ScrollView>
</Page>
</template>
<template>
<v-container grid-list-md fluid>
<v-layout wrap>
<v-flex xs6 sm4 md2 v-for="(dog, index) in dogsList" :key="dog">
<v-card>
<v-card-media
height="200px"
:src="dog"></v-card-media>
...
</v-card>
</v-flex>
</v-layout>
</v-container>
</template>
Home.vue
Home.web.vue
main.web.js
import Vue from 'vue';
import router from 'vue-router';
import Home from './components/Home';
import Vuetify from 'vuetify';
import './styles';
Vue.use(Vuetify, {
theme: {
primary: '#3f51b5',
secondary: '#b0bec5',
accent: '#8c9eff',
error: '#b71c1c'
},
});
new Vue({
el: '#app',
router,
render: h => h(Home),
});
main.native.js
import Vue from 'nativescript-vue';
import Home from './components/Home';
import './styles';
// Uncommment the following to see NativeScript-Vue output logs
Vue.config.silent = false;
new Vue({
render: h => h(Home),
}).$start();
<script>
import service from "../shared/service.vue";
export default {
mixins: [service],
created() {
this.loadDogs();
}
};
</script>
/shared/service.vue
<script>
import axios from "axios";
export default {
data () {
return {
dogsList: []
}
},
methods: {
loadDogs() {
axios
.get("https://dog.ceo/api/breeds/image/random/50")
.then(response => {
this.dogsList = response.data.message;
})
.catch(error => {
console.log(error);
});
},
}
}
</script>
page-specific scoped, or global
<style scoped>
Page {
background-color: #ffffff;
}
.action-bar {
background-color: #303F9F;
color: #C5CAE9;
}
.card{
margin: 5;
color: white;
border-radius: 5;
height:250;
}
</style>
// NativeScript core theme
@import '~nativescript-theme-core/scss/skins/light/index';
@import '~nativescript-theme-core/scss/index';
Get ready for Vue 3 and the accompanying Vue CLI 3.x
Thank you, kind sir, for the NativeScript-Vue implementation.
Hon, you look like you need a drink
By Telerik DevRel
for webinar