Loading...
Loading...
Guides the agent through Vue-specific patterns for Capacitor app development. Covers Vue 3 Composition API with Capacitor plugins, custom composables for native features, reactive plugin state, lifecycle hook patterns, Vue Router deep link integration, platform detection, PWA Elements setup, Quasar Framework integration, and Nuxt integration. Do not use for creating a new Capacitor app from scratch, upgrading Capacitor versions, installing specific plugins, Ionic Framework with Vue setup, or non-Vue frameworks.
npx skill4agent add capawesome-team/skills capacitor-vuevite.config.tsvite.config.jsquasar.config.jsquasar.config.tsnuxt.config.tspackage.jsoncapacitor.config.tscapacitor.config.jsonvuepackage.json@capacitor/corepackage.jsonquasar.config.jsquasar.config.tsreferences/quasar.mdnuxt.config.tsnuxt.config.jsreferences/nuxt.mdvite.config.tsvite.config.jsandroid/ios/capacitor.config.tscapacitor.config.jsonbuild.outDirvite.config.tsvite.config.jsdist@capacitor/corepackage.jsonreferences/quasar.mdnpm install @capacitor/core
npm install -D @capacitor/clinpx cap initdistwebDircapacitor.config.tscapacitor.config.jsoncapacitor.config.tsimport type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
appId: 'com.example.app',
appName: 'my-app',
webDir: 'dist',
};
export default config;capacitor.config.json{
"appId": "com.example.app",
"appName": "my-app",
"webDir": "dist"
}npm run build
npm install @capacitor/android @capacitor/ios
npx cap add android
npx cap add ios
npx cap syncmy-app/
├── android/ # Android native project
├── ios/ # iOS native project
├── public/
├── src/
│ ├── assets/
│ ├── components/
│ ├── composables/ # Custom composables for Capacitor plugins
│ ├── router/
│ │ └── index.ts # Vue Router configuration
│ ├── views/
│ ├── App.vue
│ └── main.ts
├── capacitor.config.ts # or capacitor.config.json
├── index.html
├── package.json
├── tsconfig.json
└── vite.config.tsandroid/ios/src/src/composables/src/<script setup lang="ts">
import { ref } from 'vue';
import { Geolocation } from '@capacitor/geolocation';
const latitude = ref<number | null>(null);
const longitude = ref<number | null>(null);
async function getCurrentPosition() {
const position = await Geolocation.getCurrentPosition();
latitude.value = position.coords.latitude;
longitude.value = position.coords.longitude;
}
</script>
<template>
<div>
<p>Latitude: {{ latitude }}</p>
<p>Longitude: {{ longitude }}</p>
<button @click="getCurrentPosition">Get Location</button>
</div>
</template>// src/composables/useCamera.ts
import { ref } from 'vue';
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
import type { Photo } from '@capacitor/camera';
export function useCamera() {
const photo = ref<Photo | null>(null);
const error = ref<string | null>(null);
async function takePhoto(): Promise<void> {
try {
error.value = null;
photo.value = await Camera.getPhoto({
quality: 90,
allowEditing: false,
resultType: CameraResultType.Uri,
source: CameraSource.Camera,
});
} catch (e) {
error.value = e instanceof Error ? e.message : String(e);
}
}
async function pickFromGallery(): Promise<void> {
try {
error.value = null;
photo.value = await Camera.getPhoto({
quality: 90,
allowEditing: false,
resultType: CameraResultType.Uri,
source: CameraSource.Photos,
});
} catch (e) {
error.value = e instanceof Error ? e.message : String(e);
}
}
return {
photo,
error,
takePhoto,
pickFromGallery,
};
}<script setup lang="ts">
import { useCamera } from '@/composables/useCamera';
const { photo, error, takePhoto } = useCamera();
</script>
<template>
<div>
<button @click="takePhoto">Take Photo</button>
<p v-if="error">Error: {{ error }}</p>
<img v-if="photo?.webPath" :src="photo.webPath" alt="Captured photo" />
</div>
</template>onMountedonUnmountedref// src/composables/useNetwork.ts
import { ref, onMounted, onUnmounted } from 'vue';
import { Network } from '@capacitor/network';
import type { ConnectionStatus } from '@capacitor/network';
import type { PluginListenerHandle } from '@capacitor/core';
export function useNetwork() {
const status = ref<ConnectionStatus | null>(null);
let listenerHandle: PluginListenerHandle | null = null;
onMounted(async () => {
status.value = await Network.getStatus();
listenerHandle = await Network.addListener('networkStatusChange', (newStatus) => {
status.value = newStatus;
});
});
onUnmounted(async () => {
await listenerHandle?.remove();
});
return {
status,
};
}<script setup lang="ts">
import { useNetwork } from '@/composables/useNetwork';
const { status } = useNetwork();
</script>
<template>
<p v-if="status">Network: {{ status.connected ? 'Online' : 'Offline' }}</p>
</template>App.vue<!-- src/App.vue -->
<script setup lang="ts">
import { onMounted, onUnmounted } from 'vue';
import { App } from '@capacitor/app';
import type { PluginListenerHandle } from '@capacitor/core';
import { RouterView } from 'vue-router';
let appStateListener: PluginListenerHandle | null = null;
onMounted(async () => {
appStateListener = await App.addListener('appStateChange', (state) => {
console.log('App state changed. Is active:', state.isActive);
});
});
onUnmounted(async () => {
await appStateListener?.remove();
});
</script>
<template>
<RouterView />
</template>Capacitor.isNativePlatform()Capacitor.getPlatform()// src/composables/usePlatform.ts
import { Capacitor } from '@capacitor/core';
export function usePlatform() {
const platform = Capacitor.getPlatform() as 'web' | 'ios' | 'android';
const isNative = Capacitor.isNativePlatform();
const isIos = platform === 'ios';
const isAndroid = platform === 'android';
const isWeb = platform === 'web';
return {
platform,
isNative,
isIos,
isAndroid,
isWeb,
};
}<script setup lang="ts">
import { usePlatform } from '@/composables/usePlatform';
const { isNative } = usePlatform();
</script>
<template>
<button v-if="isNative" @click="openNativeSettings()">Open Device Settings</button>
</template>App.addListener('appUrlOpen', ...)App.vue// src/composables/useDeepLinks.ts
import { onMounted, onUnmounted } from 'vue';
import { useRouter } from 'vue-router';
import { App } from '@capacitor/app';
import type { PluginListenerHandle } from '@capacitor/core';
export function useDeepLinks() {
const router = useRouter();
let listenerHandle: PluginListenerHandle | null = null;
onMounted(async () => {
listenerHandle = await App.addListener('appUrlOpen', (event) => {
const url = new URL(event.url);
const path = url.pathname;
// Navigate to the route matching the deep link path.
// Adjust the path parsing logic to match the app's URL scheme.
if (path) {
router.push(path);
}
});
});
onUnmounted(async () => {
await listenerHandle?.remove();
});
}App.vue<!-- src/App.vue -->
<script setup lang="ts">
import { useDeepLinks } from '@/composables/useDeepLinks';
useDeepLinks();
</script>
<template>
<RouterView />
</template>App.addListener('backButton', ...)// src/composables/useBackButton.ts
import { onMounted, onUnmounted } from 'vue';
import { useRouter } from 'vue-router';
import { App } from '@capacitor/app';
import { Capacitor } from '@capacitor/core';
import type { PluginListenerHandle } from '@capacitor/core';
export function useBackButton() {
const router = useRouter();
let listenerHandle: PluginListenerHandle | null = null;
onMounted(async () => {
if (Capacitor.getPlatform() !== 'android') {
return;
}
listenerHandle = await App.addListener('backButton', ({ canGoBack }) => {
if (canGoBack) {
router.back();
} else {
App.exitApp();
}
});
});
onUnmounted(async () => {
await listenerHandle?.remove();
});
}App.vue<!-- src/App.vue -->
<script setup lang="ts">
import { useBackButton } from '@/composables/useBackButton';
useBackButton();
</script>
<template>
<RouterView />
</template>@ionic/pwa-elementsnpm install @ionic/pwa-elementssrc/main.tscreateApp()import { createApp } from 'vue';
import { defineCustomElements } from '@ionic/pwa-elements/loader';
import App from './App.vue';
import router from './router';
defineCustomElements(window);
const app = createApp(App);
app.use(router);
app.mount('#app');npm run build
npx cap syncnpx cap run android
npx cap run iosnpx cap open android
npx cap open iosnpx cap run android --livereload --external
npx cap run ios --livereload --externalwebDirnpx cap syncwebDircapacitor.config.tscapacitor.config.jsondistnpx cap syncpackage.jsononUnmountedPluginListenerHandleaddListenerhandle.remove()android/app/src/main/AndroidManifest.xmlios/App/App/Info.plistuseDeepLinks()App.vuecanGoBackApp.exitApp()defineCustomElements(window)src/main.tscreateApp()@ionic/pwa-elementsquasar mode add capacitorreferences/quasar.mdssr: falsenuxt.config.tsreferences/nuxt.mdcapacitor-app-creationcapacitor-app-developmentcapacitor-pluginsionic-vuecapacitor-app-upgrades