【发布时间】:2019-05-21 07:36:24
【问题描述】:
如何将 VuetifyJS Advanced slots 示例与 Google Places API 一起使用?
<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>
我在 Google Developer Console 中添加了 Google Maps Geocoding API、Google Places API Web Service 和 Google Maps Javascript API,并收到了一个 API 密钥。
【问题讨论】:
-
您想从 Google Places API 中显示什么?仅表示地名或其他任何内容?
-
仅限地点(仅限文本)
-
使用 AXIOS 获取数据并直接添加 API 密钥会暴露您的 API 密钥,浏览器也会根据 CORS 策略阻止它。您需要添加服务器端代码,该代码将充当代理服务器以从 Google Places API 获取数据。
-
另外,我没有 Google Places API 的任何 API 密钥,否则我会相应地更新提供的 CodePen 中的代码。
标签: vue.js vuejs2 google-places-api vuetify.js