0
<html>
    <compornet-a></compornet-a>
    <compornet-a></compornet-a>
</html>

<template>
    <div class="contents">
        {{num}}
    </div>
</template>
<script>
    export default {
        data() {
            return {
                num: 0,  
            }
        },
        mounted() {
            testApi.then(
                (resolve) => {
                    this.num = this.num + 1;
                },
                (reject) => {
                    this.num = 0;
                },
            );
        }
    }
</script>

上記のように、同一画面に同一のコンポーネントを読み込む場合に
mountedのAPI処理が二度走るのを解消したいのですがどうしたら良いでしょうか?
extendを使用すると、templateを再定義しなければならないため避けたいです。

1 件の回答 1

0

compornet-aを埋め込んでいる側のコンポーネントのmountedでtestApiを実行して、実行結果をpropsでcompornet-aに渡せばよいのではないでしょうか?

1
  • 確かに...、めちゃめちゃシンプルな考え方ですね。
    – user16768
    2018年6月14日 9:11

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。