Как использовать пример слотов VuetifyJS Advanced с Google Places API - PullRequest
0 голосов
/ 20 декабря 2018

Как использовать пример VuetifyJS Advanced slots с Google Places API ?

Пример CodePen

<v-autocomplete
  v-model="model"
  :items="items"
  :loading="isLoading"
  :search-input.sync="search"
  chips
  clearable
  hide-details
  hide-selected
  item-text="name"
  item-value="symbol"
  label="Search for a coin..."
  solo
>
  <template slot="no-data">
    <v-list-tile>
      <v-list-tile-title>
        Search for your favorite
        <strong>Cryptocurrency</strong>
      </v-list-tile-title>
    </v-list-tile>
  </template>
  <template
    slot="selection"
    slot-scope="{ item, selected }"
  >
    <v-chip
      :selected="selected"
      color="blue-grey"
      class="white--text"
    >
      <v-icon left>mdi-coin</v-icon>
      <span v-text="item.name"></span>
    </v-chip>
  </template>
  <template
    slot="item"
    slot-scope="{ item, tile }"
  >
    <v-list-tile-avatar
      color="indigo"
      class="headline font-weight-light white--text"
    >
      {{ item.name.charAt(0) }}
    </v-list-tile-avatar>
    <v-list-tile-content>
      <v-list-tile-title v-text="item.name"></v-list-tile-title>
      <v-list-tile-sub-title v-text="item.symbol"></v-list-tile-sub-title>
    </v-list-tile-content>
    <v-list-tile-action>
      <v-icon>mdi-coin</v-icon>
    </v-list-tile-action>
  </template>
</v-autocomplete>

Я добавил API геокодирования Карт Google, веб-сервис API Google Адресов и API JavaScript Карт Google в Консоль разработчика Google и получил APIКлюч.

1 Ответ

0 голосов
/ 28 декабря 2018

Ниже приведена инструкция по интеграции компонента Vuetify Autocompletes с Google Places API:

1) добавить ссылку на Google Places API

<script src="https://maps.googleapis.com/maps/api/js?&libraries=places&key=--KEY--"></script>

2)В следующем примере показано, как заполнить v-autocomplete компонент местами, используя getPlacePredictions метод AutocompleteService class

search(val) {
  if (!val) {
      return;
  }

  this.isLoading = true;

  const service = new google.maps.places.AutocompleteService();
  service.getQueryPredictions({ input: val }, (predictions, status) => {
    if (status != google.maps.places.PlacesServiceStatus.OK) {
      return;
    }

    this.items = predictions.map(prediction => {
      return {
        id: prediction.id,
        name: prediction.description,
      };
    });

    this.isLoading = false;
  });
}

enter image description here

Демонстрация на CodePen

Предварительные условия

С Автозаполнение является функциейБиблиотека мест в JavaScript API Карт . Сначала убедитесь, что в консоли Google Cloud Platform включен API мест.Следуйте этой инструкции о том, как включить Places API

...