Help us understand the problem. What is going on with this article?

【Vuetify】`v-select`で任意の範囲の数字を選べるセレクトボックスサンプルコード

はじめに

Vuetifyのv-selectを使って、1歳から116歳までの年齢を選ぶことが出来るサンプルコードを作成しました。

環境

OS: macOS Catalina 10.15.1
Vue: 2.6.10
vue-cli: 4.1.1
vuetify: 2.1.0

出力

image.png

image.png

コード

sample.vue
<template>
  <v-select
    v-model="age"
    :items="items"
    label="年齢"
  ></v-select>
</template>

<script>
  const maxAge = 117; //表示したい数字より+1で設定。
  const ageRange = [...Array(maxAge).keys()]

  export default {
    data() {
      return {
        items: ageRange,
          age: '',
        },
      }
    },
  }
</script>

さすがに
[1,2,3,4,...117]
とはしたくなかったのでやり方を調べたら、
[...Array(数字).keys()]で整数の連番が作成できるんですね。勉強になりました。:thinking:

Rubyなら範囲オブジェクトで0..100でOKなんですけどひと手間いりますね:sweat_smile:

おわりに

最後まで読んで頂きありがとうございました:bow_tone1:

どなたかの参考になれば幸いです:relaxed:

参考にさせて頂いたサイト(いつもありがとうございます)

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした