[英]VueJS Google places autocomplete
大家好,我在执行Google自动完成功能时遇到了错误。 所以这是场景 在蓝色上可以正常工作,但是当我将其替换为红色时则无法正常工作
现在,当我将其放在红色箭头指向的行上时,出现此错误
供参考我正在使用这个: https : //www.npmjs.com/package/vue-google-autocomplete我也尝试过这个https://medium.com/dailyjs/google-places-autocomplete-in-vue-js- 350aa934b18d
它工作正常,但是当我将其放在循环中时,它无法工作。 似乎安装状态出现错误。 这是我的mount()的代码
//this is the current I used
this.$refs.address.focus();
//this is for the 2nd one
/*this.autocomplete = new google.maps.places.Autocomplete(
(this.$refs.autocomplete),
{types: ['geocode']}
);
this.autocomplete.addListener('place_changed', () => {
let place = this.autocomplete.getPlace();
let ac = place.address_components;
let lat = place.geometry.location.lat();
let lon = place.geometry.location.lng();
let city = ac[0]["short_name"];
console.log(`The user picked ${city} with the coordinates ${lat}, ${lon}`);
});*/
用以下内容替换mounted
在您内部的线路:
if(this.$refs.address) this.$refs.address.focus();
因为自动完成组件被放置在v-for
内部v-for
所以在安装WorkHistory.vue
组件时,它不知道this.$refs.address
是什么,除非work_history_data
至少包含1个项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.