diff --git a/docs/vue/your-first-app.md b/docs/vue/your-first-app.md index 1ebeda7d1b4..9eb99df9f32 100644 --- a/docs/vue/your-first-app.md +++ b/docs/vue/your-first-app.md @@ -4,10 +4,10 @@ sidebar_label: Build Your First App --- - Vue Step-by-Step Tutorial: Run Your First Ionic App with Vue + Build Your First Ionic Mobile App: Vue Development Tutorial @@ -30,9 +30,9 @@ We'll create a Photo Gallery app that offers the ability to take photos with you Highlights include: -- One Vue-based codebase that runs on the web, iOS, and Android using Ionic Framework [UI components](https://ionicframework.com/docs/components). +- One Vue-based codebase that runs on the web, iOS, and Android using Ionic Framework [UI components](../components.md). - Deployed as a native iOS and Android mobile app using [Capacitor](https://capacitorjs.com), Ionic's official native app runtime. -- 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. +- Photo Gallery functionality powered by the Capacitor [Camera](../native/camera.md), [Filesystem](../native/filesystem.md), and [Preferences](../native/preferences.md) APIs. Find the complete app code referenced in this guide [on GitHub](https://github.com/ionic-team/photo-gallery-capacitor-vue). @@ -43,9 +43,8 @@ Download and install these right away to ensure an optimal Ionic development exp - **Node.js** for interacting with the Ionic ecosystem. [Download the LTS version here](https://nodejs.org/en/). - **A code editor** for... writing code! We are fans of [Visual Studio Code](https://code.visualstudio.com/). - **Command-line interface/terminal (CLI)**: - - **Windows** users: for the best Ionic experience, we recommend the built-in command line (cmd) or the Powershell - CLI, running in Administrator mode. - - **Mac/Linux** users, virtually any terminal will work. + - **Windows** users: for the best Ionic experience, we recommend the built-in command line (cmd) or the Powershell CLI, running in Administrator mode. + - **Mac/Linux** users: virtually any terminal will work. ## Install Ionic Tooling @@ -56,7 +55,7 @@ To open a terminal in Visual Studio Code, go to Terminal -> New Terminal. ::: ```shell -npm install -g @ionic/cli@latest native-run +npm install -g @ionic/cli native-run cordova-res ``` :::note @@ -89,7 +88,7 @@ npm install @capacitor/camera @capacitor/preferences @capacitor/filesystem ### PWA Elements -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). +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). It's a separate dependency, so install it next: @@ -97,21 +96,37 @@ It's a separate dependency, so install it next: npm install @ionic/pwa-elements ``` -After installation, open up the project in your code editor of choice. - Next, import `@ionic/pwa-elements` by editing `src/main.ts`. -```tsx -// Above the createApp() line +```ts +import { createApp } from 'vue'; +import App from './App.vue'; +import router from './router'; + +import { IonicVue } from '@ionic/vue'; +// CHANGE: Add the following import. import { defineCustomElements } from '@ionic/pwa-elements/loader'; + +/* 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. */ + +/* Theme variables */ +import './theme/variables.css'; + +// CHANGE: Call the element loader before the createApp() call defineCustomElements(window); + +const app = createApp(App).use(IonicVue).use(router); + +router.isReady().then(() => { + app.mount('#app'); +}); ``` That’s it! Now for the fun part - let’s see the app in action. ## Run the App -Run this command in your shell: +Run this command next: ```shell ionic serve @@ -121,13 +136,13 @@ And voilà! Your Ionic app is now running in a web browser. Most of your app can ## Photo Gallery!!! -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! +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! ![Animated GIF showing the live reload feature in an Ionic app, with changes in code immediately updating the app in a web browser.](/img/guides/vue/first-app/live-reload.gif 'Live Reload Feature in Ionic App') -Open `/src/views/Tab2.vue`. We see: +Open `/src/views/Tab2Page.vue`. We see: -```html +```vue + + ``` -`ion-header` represents the top navigation and toolbar, with "Tab 2" as the title. Let’s rename it: +`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: -```html +```vue Photo Gallery ``` -We put the visual aspects of our app into ``. 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: +We put the visual aspects of our app into ``. 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. -```tsx -import ExploreContainer from '@/components/ExploreContainer.vue'; -``` - -Next, remove the `ExploreContainer` node from the HTML markup in the `template`. +```vue +