You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -4,13 +4,15 @@ sidebar_label: Build Your First App
4
4
---
5
5
6
6
<head>
7
-
<title>Vue Step-by-Step Tutorial: Run Your First Ionic App with Vue</title>
7
+
<title>Build Your First Ionic Mobile App with Vue | Ionic Capacitor Camera</title>
8
8
<meta
9
9
name="description"
10
-
content="This Vue tutorial, teaches the fundamentals of Ionic app development by creating a realistic app step-by-step. Learn to run your first Ionic app with Vue."
10
+
content="This Vue tutorial teaches the fundamentals of Ionic app development by creating a realistic app step-by-step. Learn to run your first Ionic app with Vue."
11
11
/>
12
12
</head>
13
13
14
+
# Your First Ionic App: Vue
15
+
14
16
The great thing about Ionic is that with one codebase, you can build for any platform using just HTML, CSS, and JavaScript. Follow along as we learn the fundamentals of Ionic app development by creating a realistic app step by step.
15
17
16
18
Here’s the finished app running on all 3 platforms:
@@ -19,9 +21,9 @@ Here’s the finished app running on all 3 platforms:
@@ -30,11 +32,11 @@ We'll create a Photo Gallery app that offers the ability to take photos with you
30
32
31
33
Highlights include:
32
34
33
-
- One Vue-based codebase that runs on the web, iOS, and Android using Ionic Framework [UI components](https://ionicframework.com/docs/components).
35
+
- One Vue-based codebase that runs on the web, iOS, and Android using Ionic Framework [UI components](../components.md).
34
36
- Deployed as a native iOS and Android mobile app using [Capacitor](https://capacitorjs.com), Ionic's official native app runtime.
35
-
- Photo Gallery functionality powered by the Capacitor [Camera](https://capacitorjs.com/docs/apis/camera), [Filesystem](https://capacitorjs.com/docs/apis/filesystem), and [Preferences](https://capacitorjs.com/docs/apis/preferences) APIs.
37
+
- Photo Gallery functionality powered by the Capacitor [Camera](../native/camera.md), [Filesystem](../native/filesystem.md), and [Preferences](../native/preferences.md) APIs.
36
38
37
-
Find the complete app code referenced in this guide [on GitHub](https://github.com/ionic-team/photo-gallery-capacitor-vue).
39
+
Find the [complete app code](https://github.com/ionic-team/photo-gallery-capacitor-vue) referenced in this guide on GitHub.
38
40
39
41
## Download Required Tools
40
42
@@ -43,9 +45,8 @@ Download and install these right away to ensure an optimal Ionic development exp
43
45
-**Node.js** for interacting with the Ionic ecosystem. [Download the LTS version here](https://nodejs.org/en/).
44
46
-**A code editor** for... writing code! We are fans of [Visual Studio Code](https://code.visualstudio.com/).
45
47
-**Command-line interface/terminal (CLI)**:
46
-
-**Windows** users: for the best Ionic experience, we recommend the built-in command line (cmd) or the Powershell
47
-
CLI, running in Administrator mode.
48
-
-**Mac/Linux** users, virtually any terminal will work.
48
+
-**Windows** users: for the best Ionic experience, we recommend the built-in command line (cmd) or the Powershell CLI, running in Administrator mode.
49
+
-**Mac/Linux** users: virtually any terminal will work.
49
50
50
51
## Install Ionic Tooling
51
52
@@ -56,7 +57,7 @@ To open a terminal in Visual Studio Code, go to Terminal -> New Terminal.
Some Capacitor plugins, including the Camera API, provide the web-based functionality and UI via the Ionic [PWA Elements library](https://github.com/ionic-team/pwa-elements).
93
+
Some Capacitor plugins, including the [Camera API](../native/camera.md), provide the web-based functionality and UI via the Ionic [PWA Elements library](https://github.com/ionic-team/pwa-elements).
93
94
94
95
It's a separate dependency, so install it next:
95
96
96
97
```shell
97
98
npm install @ionic/pwa-elements
98
99
```
99
100
100
-
After installation, open up the project in your code editor of choice.
101
-
102
101
Next, import `@ionic/pwa-elements` by editing `src/main.ts`.
/* Ionic styles are not shown in this example to keep it brief but will be included in the Ionic package downloaded for your app. Do not remove them. */
113
+
114
+
/* Theme variables */
115
+
import'./theme/variables.css';
116
+
117
+
// CHANGE: Call the element loader before the createApp() call
That’s it! Now for the fun part - let’s see the app in action.
111
128
112
129
## Run the App
113
130
114
-
Run this command in your shell:
131
+
Run this command next:
115
132
116
133
```shell
117
134
ionic serve
@@ -121,13 +138,13 @@ And voilà! Your Ionic app is now running in a web browser. Most of your app can
121
138
122
139
## Photo Gallery!!!
123
140
124
-
There are three tabs. Click on the Tab2 tab. It’s a blank canvas, aka the perfect spot to transform into a Photo Gallery. The Ionic CLI features Live Reload, so when you make changes and save them, the app is updated immediately!
141
+
There are three tabs. Click on the "Tab2" tab. It’s a blank canvas, aka the perfect spot to transform into a Photo Gallery. The Ionic CLI features Live Reload, so when you make changes and save them, the app is updated immediately!
125
142
126
143

127
144
128
-
Open `/src/views/Tab2.vue`. We see:
145
+
Open `/src/views/Tab2Page.vue`. We see:
129
146
130
-
```html
147
+
```vue
131
148
<template>
132
149
<ion-page>
133
150
<ion-header>
@@ -146,30 +163,53 @@ Open `/src/views/Tab2.vue`. We see:
146
163
</ion-content>
147
164
</ion-page>
148
165
</template>
166
+
167
+
<script setup lang="ts">
168
+
import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/vue';
169
+
import ExploreContainer from '@/components/ExploreContainer.vue';
170
+
</script>
149
171
```
150
172
151
-
`ion-header` represents the top navigation and toolbar, with "Tab 2" as the title. Let’s rename it:
173
+
`ion-header` represents the top navigation and toolbar, with "Tab 2" as the title (there are two of them due to iOS [Collapsible Large Title](../api/title.md#collapsible-large-titles) support). Rename both `ion-title` elements to:
152
174
153
-
```html
175
+
```vue
154
176
<ion-title>Photo Gallery</ion-title>
155
177
```
156
178
157
-
We put the visual aspects of our app into `<ion-content>`. In this case, it’s where we’ll add a button that opens the device’s camera as well as displays the image captured by the camera. But first, remove the `ExploreContainer` component, beginning with the import statement:
179
+
We put the visual aspects of our app into `<ion-content>`. In this case, it’s where we’ll add a button that opens the device’s camera as well as displays the image captured by the camera. Start by adding a [floating action button](../api/fab.md) (FAB) to the bottom of the page and set the camera image as the icon.
We'll replace it with a [floating action button](https://ionicframework.com/docs/api/fab) (FAB). First, update the imports within the `<script setup>` tag to include the Camera icon as well as some of the Ionic components we'll use shortly:
203
+
<!-- CHANGE: Remove or comment out <ExploreContainer /> -->
204
+
<!-- <ExploreContainer name="Tab 2 page" /> -->
205
+
</ion-content>
206
+
</ion-page>
207
+
</template>
170
208
171
-
```tsx
209
+
<script setup lang="ts">
210
+
// CHANGE: Add import from `ionicons/icons`
172
211
import { camera, trash, close } from 'ionicons/icons';
212
+
// CHANGE: Update import from `@ionic/vue` to include necessary Ionic components.
173
213
import {
174
214
IonPage,
175
215
IonHeader,
@@ -184,37 +224,45 @@ import {
184
224
IonCol,
185
225
IonImg,
186
226
} from '@ionic/vue';
227
+
// CHANGE: Remove or comment out the ExploreContainer import.
228
+
// import ExploreContainer from '@/components/ExploreContainer.vue';
229
+
</script>
187
230
```
188
231
189
-
Since our pages are generated as [Vue Single File Components](https://vuejs.org/api/sfc-spec.html) using the [`<script setup>`](https://vuejs.org/api/sfc-script-setup.html#script-setup) syntax these items are now exposed for use in our template.
232
+
Next, open `src/views/TabsPage.vue`. Change the label to "Photos" and the `ellipse` icon to `images`for the middle tab button.
190
233
191
-
Add the FAB to the bottom of the page. Use the camera image as the icon, and call the `takePhoto()` function when this button is clicked (to be implemented soon):
// CHANGE: Update import by removing `ellipse` and adding `images`.
208
264
import { images, square, triangle } from 'ionicons/icons';
265
+
</script>
209
266
```
210
267
211
-
Within the tab bar (`<ion-tab-bar>`), change the label to "Photos" and the `ellipse` icon to `images` for the middle tab button:
212
-
213
-
```html
214
-
<ion-tab-buttontab="tab2"href="/tabs/tab2">
215
-
<ion-icon:icon="images" />
216
-
<ion-label>Photos</ion-label>
217
-
</ion-tab-button>
218
-
```
219
-
220
-
That’s just the start of all the cool things we can do with Ionic. Up next, implementing camera taking functionality on the web, then building for iOS and Android.
268
+
That’s just the start of all the cool things we can do with Ionic. Up next, implement camera taking functionality on the web, then build it for iOS and Android.
0 commit comments