LoginSignup
1
1

More than 3 years have passed since last update.

googleスプレッドシートのデータをjsonで吐き出して、NUXTでセクションごとにリスト表示する

Last updated at Posted at 2020-07-30

スプレッドシートのデータを取得して、データをセクションごとにリスト表示させたのを忘れないようメモ。
axiosでGETしてくるとこが遅いので改善したい。

スプレッドシートに表を用意

スクリーンショット 2020-07-30 9.23.51.png

データをjson形式で出力。

方法はここを参考。
https://qiita.com/YukiIchika/items/778856a7ea92e5a2383c

NUXT側でデータを取得する。

ここを参考。
https://ma-vericks.com/nuxt-axios/

vueファイル内で

export default {
  async asyncData({ $axios }) {
    const url = 'https://script.google.com/macros/s/ID/exec';
    // リクエスト(Get)
    const response = await $axios.$get(url);
    // 配列で返ってくるのでJSONにして返却
    return { result: response }
  }
};
</script>

セクションごとにリスト表示させる

これのためにsectionsKeyを設定しておく。

<ul>
  <template v-for="item in result">
    <template v-if="item.sectionsKey === 1">
      <li>
        <nuxt-link :to="item.url">{{ item.pages }}</nuxt-link>
      </li>
    </template>
  </template>
</ul>
1
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1