<script setup>
import { reactive } from 'vue'
const poem = reactive({
  title: '雨霖铃·寒蝉凄切',
  body: [
    '寒蝉凄切，对长亭晚，骤雨初歇。',
    '都门帐饮无绪，留恋处，兰舟催发。',
    '执手相看泪眼，竟无语凝噎。',
    '念去去，千里烟波，暮霭沉沉楚天阔。',
    '多情自古伤离别，更那堪，冷落清秋节！',
    '今宵酒醒何处？杨柳岸，晓风残月。',
    '此去经年，应是良辰好景虚设。',
    '便纵有千种风情，更与何人说？'
  ]
})

console.log(poem.body)
</script>

<template>
  <div class="poem">
    <h2 class="poem_title">{{ poem.title }}</h2>
    <ul class="poem_body">
      <li v-for="(line, index) in poem.body" :key="index">
        <span
          v-for="(char, charIndex) in line.split('')"
          :key="charIndex"
          :style="{ animationDelay: charIndex * 0.1 + 's' }"
          >{{ char }}</span
        >
      </li>
    </ul>
  </div>
</template>

<style scoped>
* {
  box-sizing: border-box;
  font-family: 'Ma Shan Zheng', cursive;
  margin: 0;
  padding: 0;
  color: #000;
}

ol,
ul {
  list-style: none;
}

.poem {
  width: 280px;
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.4);
  text-align: center;
  > .poem_title {
    white-space: nowrap;
    padding-top: 10px;
    font-size: 24px;
    width: 100%;
  }
  > .poem_body {
    text-align: center;
    white-space: nowrap;
    font-size: 16px;
    padding: 10px 0;

    > li {
      margin: 5px auto;
    }

    > li span {
      opacity: 0;
      animation: fadeIn 1s forwards;
    }
  }
}

@keyframes fadeIn {
  to {
    opacity: 1;
  }
}
</style>
