Install Capacitor.
Add Capacitor to your project and create a config for your app
npm install @capacitor/core @capacitor/cli
npx cap init [name] [id] --web-dir=dist
Build native mobile apps with web technology and Vue
Add Capacitor to your project and create a config for your app
npm install @capacitor/core @capacitor/cli
npx cap init [name] [id] --web-dir=dist
The compiled web assets will be copied into each Capacitor native platform during the next step.
npm run build
Capacitor's native projects exist in their own top-level folders and should be considered part of your app (check them into source control).
npm i @capacitor/ios @capacitor/android
npx cap add android
npx cap add ios
With Capacitor installed, adding calls to native device features is as straight forward as calling other JavaScript methods
<template>
<div>
<h1>Geolocation</h1>
<p>Your location is:</p>
<p>Latitude: {{ loc.lat }}</p>
<p>Longitude: {{ loc.long }}</p>
<button @click="getCurrentPosition">
Get Current Location
</button>
</div>
</template>
<script>
import { defineComponent, ref } from 'vue';
import { Geolocation } from '@capacitor/geolocation';
export default defineComponent({
setup() {
const loc = ref<{
lat: null | number;
long: null | number;
}>({
lat: null,
long: null,
});
const getCurrentPosition = async () => {
const pos = await Geolocation.getCurrentPosition();
loc.value = {
lat: pos.coords.latitude,
long: pos.coords.longitude,
};
};
return { getCurrentPosition, loc };
},
});
</script>
This is only the beginning. Learn more about the Capacitor development workflow or using more native APIs .