Skip to content

Commit fb6d382

Browse files
docs: add vue example (#13)
Co-authored-by: Pedro Bilro <[email protected]>
1 parent eba1e97 commit fb6d382

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,57 @@ const MyMap: React.FC = () => {
245245
export default MyMap;
246246
```
247247

248+
### Vue
249+
250+
```vue
251+
<script lang="ts" setup>
252+
import { ref, shallowRef, useTemplateRef } from 'vue'
253+
import { GoogleMap } from '@capacitor/google-maps'
254+
255+
const mapRef = useTemplateRef<HTMLElement>('mapRef')
256+
const newMap = shallowRef<GoogleMap>()
257+
258+
async function createMap() {
259+
if (!mapRef.value) return
260+
261+
newMap.value = await GoogleMap.create({
262+
id: 'my-cool-map',
263+
element: mapRef.value,
264+
apiKey: import.meta.env.VITE_YOUR_API_KEY_HERE,
265+
config: {
266+
center: {
267+
lat: 33.6,
268+
lng: -117.9,
269+
},
270+
zoom: 8,
271+
},
272+
})
273+
}
274+
</script>
275+
276+
<template>
277+
<capacitor-google-map
278+
ref="mapRef"
279+
style="display: inline-block; width: 275px; height: 400px"
280+
></capacitor-google-map>
281+
<button @click="createMap()">Create Map</button>
282+
</template>
283+
284+
```
285+
286+
make sure you need enable [recognize native custom elements](https://vuejs.org/guide/extras/web-components.html#using-custom-elements-in-vue) like
287+
288+
```ts
289+
// vite.config.mts > plugins
290+
Vue({
291+
template: {
292+
compilerOptions: {
293+
isCustomElement: (tag) => tag.startsWith('capacitor-')
294+
},
295+
},
296+
}),
297+
```
298+
248299
### Javascript
249300

250301
```html

0 commit comments

Comments
 (0)