Skip to content

feat(vue): use the script setup syntax for single file components #1750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions vue/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
"@vue/cli-plugin-typescript": "~5.0.0-rc.1",
"@vue/cli-plugin-unit-jest": "~5.0.0-rc.1",
"@vue/cli-service": "~5.0.0-rc.1",
"@vue/eslint-config-typescript": "^9.1.0",
"@vue/eslint-config-typescript": "^11.0.2",
"@vue/test-utils": "^2.0.0-rc.16",
"@vue/vue3-jest": "^27.0.0-alpha.3",
"babel-jest": "^27.3.1",
"cypress": "^8.7.0",
"eslint": "^8.4.1",
"eslint-plugin-vue": "^8.2.0",
"eslint-plugin-vue": "^9.8.0",
"jest": "^27.3.1",
"ts-jest": "^27.0.7",
"typescript": "^4.3.5"
Expand Down
13 changes: 2 additions & 11 deletions vue/official/blank/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
</ion-app>
</template>

<script lang="ts">
<script setup lang="ts">
import { IonApp, IonRouterOutlet } from '@ionic/vue';
import { defineComponent } from 'vue';

export default defineComponent({
name: 'App',
components: {
IonApp,
IonRouterOutlet
}
});
</script>
</script>
18 changes: 3 additions & 15 deletions vue/official/blank/src/views/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<ion-title>Blank</ion-title>
</ion-toolbar>
</ion-header>

<ion-content :fullscreen="true">
<ion-header collapse="condense">
<ion-toolbar>
<ion-title size="large">Blank</ion-title>
</ion-toolbar>
</ion-header>

<div id="container">
<strong>Ready to create an app?</strong>
<p>Start with Ionic <a target="_blank" rel="noopener noreferrer" href="https://ionicframework.com/docs/components">UI Components</a></p>
Expand All @@ -21,20 +21,8 @@
</ion-page>
</template>

<script lang="ts">
<script setup lang="ts">
import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar } from '@ionic/vue';
import { defineComponent } from 'vue';

export default defineComponent({
name: 'HomePage',
components: {
IonContent,
IonHeader,
IonPage,
IonTitle,
IonToolbar
}
});
</script>

<style scoped>
Expand Down
13 changes: 2 additions & 11 deletions vue/official/list/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
</ion-app>
</template>

<script lang="ts">
<script setup lang="ts">
import { IonApp, IonRouterOutlet } from '@ionic/vue';
import { defineComponent } from 'vue';

export default defineComponent({
name: 'App',
components: {
IonApp,
IonRouterOutlet
}
});
</script>
</script>
34 changes: 10 additions & 24 deletions vue/official/list/src/components/MessageListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,18 @@
</ion-item>
</template>

<script lang="ts">
<script setup lang="ts">
import { IonIcon, IonItem, IonLabel, IonNote } from '@ionic/vue';
import { chevronForward } from 'ionicons/icons';
import { defineComponent } from 'vue';

export default defineComponent({
name: 'MessageListItem',
components: {
IonIcon,
IonItem,
IonLabel,
IonNote,
},
props: {
message: Object,
},
methods: {
isIos: () => {
const win = window as any;
return win && win.Ionic && win.Ionic.mode === 'ios';
}
},
data() {
return { chevronForward }
}
defineProps({
message: Object,
});

const isIos = () => {
const win = window as any;
return win && win.Ionic && win.Ionic.mode === 'ios';
};
</script>

<style scoped>
Expand All @@ -56,7 +42,7 @@ export default defineComponent({
margin-bottom: 12px;
}

.list-item h2 {
.list-item h2 {
font-weight: 600;
margin: 0;
}
Expand Down Expand Up @@ -100,4 +86,4 @@ export default defineComponent({
.list-item .dot-unread {
background: var(--ion-color-primary);
}
</style>
</style>
56 changes: 23 additions & 33 deletions vue/official/list/src/views/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,45 @@
<ion-title>Inbox</ion-title>
</ion-toolbar>
</ion-header>

<ion-content :fullscreen="true">
<ion-refresher slot="fixed" @ionRefresh="refresh($event)">
<ion-refresher-content></ion-refresher-content>
</ion-refresher>

<ion-header collapse="condense">
<ion-toolbar>
<ion-title size="large">Inbox</ion-title>
</ion-toolbar>
</ion-header>

<ion-list>
<MessageListItem v-for="message in messages" :key="message.id" :message="message" />
</ion-list>
</ion-content>
</ion-page>
</template>

<script lang="ts">
import { IonContent, IonHeader, IonList, IonPage, IonRefresher, IonRefresherContent, IonTitle, IonToolbar } from '@ionic/vue';
<script setup lang="ts">
import {
IonContent,
IonHeader,
IonList,
IonPage,
IonRefresher,
IonRefresherContent,
IonTitle,
IonToolbar,
} from '@ionic/vue';
import MessageListItem from '@/components/MessageListItem.vue';
import { defineComponent } from 'vue';
import { getMessages } from '@/data/messages';
import { getMessages, Message } from '@/data/messages';
import { ref } from 'vue';

const messages = ref<Message[]>(getMessages());

export default defineComponent({
name: 'HomePage',
data() {
return {
messages: getMessages()
}
},
methods: {
refresh: (ev: CustomEvent) => {
setTimeout(() => {
ev.detail.complete();
}, 3000);
}
},
components: {
IonContent,
IonHeader,
IonList,
IonPage,
IonRefresher,
IonRefresherContent,
IonTitle,
IonToolbar,
MessageListItem
},
});
const refresh = (ev: CustomEvent) => {
setTimeout(() => {
ev.detail.complete();
}, 3000);
};
</script>
57 changes: 22 additions & 35 deletions vue/official/list/src/views/ViewMessagePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</ion-buttons>
</ion-toolbar>
</ion-header>

<ion-content :fullscreen="true" v-if="message">
<ion-item>
<ion-icon :icon="personCircle" color="primary"></ion-icon>
Expand All @@ -21,7 +21,7 @@
<h3>To: <ion-note>Me</ion-note></h3>
</ion-label>
</ion-item>

<div class="ion-padding">
<h1>{{ message.subject }}</h1>
<p>
Expand All @@ -32,44 +32,31 @@
</ion-page>
</template>

<script lang="ts">
<script setup lang="ts">
import { useRoute } from 'vue-router';
import { IonBackButton, IonButtons, IonContent, IonHeader, IonIcon, IonItem, IonLabel, IonNote, IonPage, IonToolbar } from '@ionic/vue';
import {
IonBackButton,
IonButtons,
IonContent,
IonHeader,
IonIcon,
IonItem,
IonLabel,
IonNote,
IonPage,
IonToolbar,
} from '@ionic/vue';
import { personCircle } from 'ionicons/icons';
import { getMessage } from '../data/messages';
import { defineComponent } from 'vue';

export default defineComponent({
name: 'ViewMessagePage',
data() {
return {
personCircle,
getBackButtonText: () => {
const win = window as any;
const mode = win && win.Ionic && win.Ionic.mode;
return mode === 'ios' ? 'Inbox' : '';
}
}
},
setup() {
const route = useRoute();
const message = getMessage(parseInt(route.params.id as string, 10));
const getBackButtonText = () => {
const win = window as any;
const mode = win && win.Ionic && win.Ionic.mode;
return mode === 'ios' ? 'Inbox' : '';
};

return { message }
},
components: {
IonBackButton,
IonButtons,
IonContent,
IonHeader,
IonIcon,
IonItem,
IonLabel,
IonNote,
IonPage,
IonToolbar,
},
});
const route = useRoute();
const message = getMessage(parseInt(route.params.id as string, 10));
</script>

<style scoped>
Expand Down
Loading