0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

vue 単一ファイルコンポーネントで、文字列配列を表示

Posted at

templateでString arrayを表示するメモ。
v-forのindexを:keyとして使う。これがベストかは不明。。

<template>
  <div>
    <li class="greeting" v-for="(item, index) in greetings" :key="index">{{ item }}</li>
    <button v-on:click="add">timestamp</button>
  </div>
</template>
<script>
export default {
  name: "Time",
  data: function() {
    return {
      greetings: []
    };
  },
  methods:{
    add: function(){
      this.greetings.push(new Date());
      if(this.greetings.length > 3){
        this.greetings.shift()
      }
    }
  }
};
</script>

0
1
0

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?