Incorporating VueJS Components from Google Maps (using vue2-google-maps) into a Laravel blade template

I recently added a Google Maps Vue JS component to my Laravel application using the vue2-google-maps npm package.

Following the instructions in the npm package documentation, I loaded the vue components like this:

import * as VueGoogleMaps from 'vue2-google-maps';

Vue.use(VueGoogleMaps, {
  load: {
    key: 'mapkey',
    libraries: 'places'
  }
});

Then, in my blade view, I used the components as shown in the documentation example:

    <GmapMap
      :center="{lat:10, lng:10}"
      :zoom="7"
      map-type-id="terrain"
      style="width: 100%; height: 500px" 
      id="googleMap"
    >
        <GmapMarker
            :key="index"
            v-for="(m, index) in mapPoints"
            :position="m.position"
            :clickable="true"
            :draggable="true"
            @click="center=m.position"
        >
        </GmapMarker>
    </GmapMap>

However, I encountered an error saying:

Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.


In my search for a solution, I found a helpful post that suggested using different component names. I tried using gmap-map & gmap-marker, but unfortunately, the error persisted.

<gmap-map
  :center="center"
  :zoom="12"
  style="width:100%;  height: 400px;"
>
  <gmap-marker
    :key="index"
    v-for="(m, index) in markers"
    :position="m.position"
    @click="center=m.position"
  ></gmap-marker>
</gmap-map>

I also attempted importing the Map And Marker components directly instead of recursively, but again, I faced the same error:

import GmapMap from 'vue2-google-maps/src/components/map';
import GmapMarker from 'vue2-google-maps/src/components/marker';

Vue.component('GmapMap', GmapMap);
Vue.component('GmapMarker', GmapMarker);

I'm unsure of what I might be doing incorrectly. Any insights would be greatly appreciated!

Answer №1

For the plugin to install components, the installComponents option must be set to true.

Check out the GitHub link for more details

import * as VueGoogleMaps from 'vue2-google-maps';

Vue.use(VueGoogleMaps, {
  load: {
    key: 'mapkey',
    libraries: 'places'
  },
  installComponents: true
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for establishing a connection between a websocket and an external API?

Currently, I have a route configured to fetch the weather data for a specific city using the openweathermap API Here is the code snippet from my index.js file: var express = require("express"), router = express.Router(); var weather = require("ope ...

"Utilizing Bootstrap Modal for efficient AJAX saving of multiple records with the help of bootstrapValidator

I'm encountering an issue with a bootstrap modal form and validation using bootstrapValidator. The problem I'm facing is that when I open the modal, fill out the fields, close it, reopen it, refill the fields, and submit the form, my script inser ...

Monitoring the loading progress of multiple files using Three JS

Just starting out with Three JS and I'm on a mission to create a loading screen that displays the progress of assets being loaded for a scene. I have a total of 7 different types of assets, including: 4 GLB files 2 Texture files And 1 Obj file Acco ...

Show an image in a specific location on the webpage using JavaScript/jQuery

Is there a way for me to show a visual element at specific coordinates on the browser screen? For example, let's say I have calculated dynamic offsets of { left: 336, top: 378 }, and I would like to display a small line or image at that position. Is ...

Exploring JSON data for auto-complete suggestions

Upon receiving the object from the source, it looks like this - ["road",[["road",53,"0E"],["roadtrip",53,"1E"],["roadrunner",53,"2E"],["roadster",53,"3E"],["roadside",53,"4E"],["roadrage",53,"5E"],["roadcycling",53,"6E"],["roadsideamerica",53,"7E"]],{"k": ...

The state object in Next.js appears to be missing

const [ values , setValues ] = React.useState({ input_type: '', elements: [] }) const addOption = () => { let newElements = values.elements newElements.push({ type: "option", ...

The data provided is not in the correct format for a timestamp

Currently, I am utilizing the pg node module to establish a connection with PostgreSQL, and I have been attempting to run the following query: const res = await client.query(`SELECT number_transactions FROM transaction.city_unique_dates WHERE date_day_t ...

Replacing URLs in Typescript using Ionic 3 and Angular

Currently facing some difficulties getting this simple task to work... Here is the URL format I am dealing with: https://website.com/image{width}x{height}.jpg My objective is to replace the {width} and {height} placeholders. I attempted using this func ...

Vue.js - Implementing multiple values (array) for a component through a property

I am currently working with vue.js components that receive their data from external sources. For example: <vue-button icon="fa-arrow-right" text="mytext"></vue-button> Initially, this setup is effective. However, I encountered a challenge wh ...

I am facing an issue with the clearTimeout function in my JavaScript code. Can anyone help

I am encountering some issues with the clearTimeout() function. The setTimeout() function is working as expected, but I want it to stop running when I close my notification. I'm not sure what is causing the problem in my function. After closing the ...

Issue encountered while creating a token in a JavaScript Chrome extension and attempting to validate it on a backend Node.js server

Trying to create a token within a chrome extension and utilizing it to authenticate requests to the backend server has proven challenging. While successfully generating a token on the front end, encountering an error when verifying it with the google-auth- ...

Handling the onChange event in ReactJS using Typescript and Redux for number values with comma separators

Consider the following scenario: I am working on a reactjs/redux/typescript application. I have implemented two-way binding with redux for my input textboxes using the onChange event. The props are all declared with the data type "number" and everything i ...

Having trouble deactivating date selections in Vue.js Material Datepicker

Can someone assist with the following HTML code: <datepicker :date="child" :option="option" v-model="child.dob" @change="updatechildDOB(child)" :disabled="disabled"></datepicker> Here are the available options: option: { type: 'd ...

What is the importance of having the http module installed for our Node.js application to function properly?

After exploring numerous sources, I stumbled upon this code snippet in the first application: var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); r ...

update the element that acts as the divider in a web address (Angular)

Is it possible to modify the separator character used when obtaining the URL parameters with route.queryParams.subscribe? Currently, Object.keys(params) separates the parameters using "&" as the separator. Is there a way to change this to use a differe ...

Make the pie charts created by progressbar.js larger by increasing their width and height

I have implemented an animated pie chart using the jQuery-plugin-progressbar found at https://github.com/yxfanxiao/jQuery-plugin-progressbar with the following code snippets: JS: ; (function ($) { $.fn.loading = function () { var DEFAULTS ...

Having an issue with the jQuery click function not functioning as expected in combination with

I have an HTML component with a button that is supposed to alert a message when clicked, but it's not working as expected. Currently, I have bound the button to a click function. Click here for demo HTML:- <div class="row row-bordered"> ...

Adjust the transparency and add animation effects using React JS

When working on a React project, I encountered an issue where a square would appear under a paragraph when hovered over and disappear when no longer hovered. However, the transition was too abrupt for my liking, so I decided to implement a smoother change ...

What is the process for setting data to the value attribute in an input tag, retrieved from a firebase database?

I utilized the following code snippet to retrieve data from Firebase database and store it in the Name variable. var userId = localStorage.getItem('keyName'); var dbRefName = firebase.database().ref() .child(& ...

JavaScript/jquery loop with an increasing index each iteration

I am currently working with a JSON file that contains paths to various images. I want to regularly add more image paths to this file and display them on an HTML page. However, I am encountering an issue when using the $.each method - the index remains the ...