1.4.1 • Published 3 years ago

dgtek-google-autocomplete v1.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

dgtek-google-autocomplete

Vue, Vuetify

Package installation

yarn add dgtek-google-autocomplete && rm -r node_modules/dgtek-google-autocomplete/dist/node_modules
package.json for auto-depoy (CI/CD):

for vue-cli:

"scripts": {
  ...
  "serve": "yarn add dgtek-google-autocomplete && rm -r node_modules/dgtek-google-autocomplete/node_modules && vue-cli-service serve",
  "build": "yarn add dgtek-google-autocomplete && rm -r node_modules/dgtek-google-autocomplete/node_modules && vue-cli-service build",
  ...
}

Start package

import 'dgtek-google-autocomplete/dist/dgtek-google-autocomplete.css'
/* ... other imports here */
const { DgtekGoogleAutocomplete } = require('dgtek-google-autocomplete').default

Set API host

window.dispatchEvent(new CustomEvent('set-api-host', {
  detail: {
    host: 'https://example.com' /* API host url must be here */
  }
}))

You should wait for Google maps script has been loaded in your component

data
data: () => ({
  mapIsReady: false,
  /* ... other variables here */
})
Catch event

You can change the name of this method (catchEvent) to your own

methods: {
  /* your own methods here */,
  catchEvent () {
    const { address, addressComponents, status, url, coordinates, buildingId, error } = event.detail
    ... /* your code will be here */
  }
}

During checking the address, a number of requests will be made to remote server. Every request can fail. error field value should be null otherwise this field contains error message

mounted hook
mounted () {
  function waitForGoogleMapsScript () {
    if (!window.google) window.requestAnimationFrame(waitForGoogleMapsScript.bind(this))
    else this.mapIsReady = true
  }

  window.requestAnimationFrame(waitForGoogleMapsScript.bind(this))

  window.addEventListener('new-address-data', this.catchEvent)
}
beforeDestroy hook
beforeDestroy () {
  ...
  window.removeEventListener('new-address-data', this.catchEvent)
}

And then insert this package to your component template:

<DgtekGoogleAutocomplete v-if="mapIsReady" />
1.4.1

3 years ago

1.1.94

3 years ago

1.1.9

3 years ago

1.1.91

3 years ago

1.1.89

3 years ago

1.1.88

3 years ago

1.1.81

3 years ago

1.1.85

3 years ago

1.1.84

3 years ago

1.1.87

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.74

3 years ago

1.1.73

3 years ago

1.1.72

3 years ago

1.1.71

3 years ago

1.1.1

3 years ago

1.1.4

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.89

3 years ago

1.0.88

3 years ago

1.0.87

3 years ago

1.0.85

3 years ago

1.0.84

3 years ago

1.0.81

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago