link411 link412 link413 link414 link415 link416 link417 link418 link419 link420 link421 link422 link423 link424 link425 link426 link427 link428 link429 link430 link431 link432 link433 link434 link435 link436 link437 link438 link439 link440 link441 link442 link443 link444 link445 link446 link447 link448 link449 link450 link451 link452 link453 link454 link455 link456 link457 link458 link459 link460 link461 link462 link463 link464 link465 link466 link467 link468 link469 link470 link471 link472 link473 link474 link475 link476 link477 link478 link479 link480 link481 link482 link483 link484 link485 link486 link487 link488 link489 link490 link491 link492 link493 link494 link495 link496 link497 link498 link499 link500 link501 link502 link503 link504 link505 link506 link507 link508 link509 link510 link511 link512 link513 link514 link515 link516 link517 link518 link519 link520 link521 link522 link523 link524 link525 link526 link527 link528 link529 link530 link531 link532 link533 link534 link535 link536 link537 link538 link539 link540 link541 link542 link543 link544 link545 link546 link547

[Vue.js] can't use passed prop in child's method {} vue.js Subscribe to RSS

I pass the array to child as prop. And trying to use it in google map method. But when I use it inside initMap: function the array being empty.

in parent

<div class=”mapWrap”>
<mapping :articles=”filterArticles” />

computed: {
let api = this.$store.getters.articles;

let filteredStates = api.filter((article) => {
return (this.keyword.length === 0 || article.address.includes(this.keyword)) &&
(this.regions.length === 0 || this.regions.includes(article.region)) &&
(this.rooms.length === 0 || this.rooms.includes(article.rooms1)) &&
( === 0 ||

return filteredStates;

in child

props: {
articles: {
return {
methods: {
initMap: function() {
var mapOptions = {
mapTypeId: ‘roadmap’,
center: new google.maps.LatLng(35.652832, 139.839478),
zoom: 10

var map = new google.maps.Map(document.getElementById(“map”), mapOptions);

var articles = this.articles;


The way when doing it wrong? Because prop has the items but when I put it inside the initMap method, it starts being empty…

Solution :

there is tried to trace the code and from what you have, it will work in most cases EXCEPT if the data that you have fetched using this.$store.getters.articles is async. Ideally, you should not be relying on the child component’s mount event because it can get mounted way before you can display any data. To verify that, you can add a console.log(this.articles) inside the mounted hook and see that it’s most likely empty.

What I suggest you do is, given that in the parent component you have articles as a computed property (which is reactive), you should also call the initMap inside the child every time the prop articles changes. The easiest way to do just that is with a watcher inside the child component:

watch: {
articles () {