首页列表组件编写

文章描述了在Vue应用中如何通过组件间通信,如`src/components/DayPage/List/item.vue`和`DayList`组件,使用props属性来传递数据并展示在`DayPage`组件的列表中,如当前年月、农历年份等信息。
摘要由CSDN通过智能技术生成

src\components\DayPage\List\item.vue

<template>
  <div class="list-item">
    <div class="block title">{{title}}</div>
    <div class="block content">{{content}}</div>
  </div>
</template>

<script>
  export default {
    name: 'ListItem',
    props: {
      title: String,
      content: String
    }
  }
</script>

src\components\DayPage\List\index.vue

<template>
  <div class="day-list">
    <list-item title="当前年月" :content="data['year-month']" />
    <list-item title="今年属相" :content="data.animalsYear" />
    <list-item title="农历年份" :content="data.lunarYear" />
    <list-item title="宜" :content="data.suit" />
    <list-item title="忌" :content="data.avoid" />
  </div>
</template>

<script>
import ListItem from "./item";
export default {
  name: "DayList",
  props: {
    data: Object,
  },
  components: {
    ListItem,
  },
};
</script>

src\views\Day.vue

首页

<template>
  <div class="container">
    <day-card :data='dayData'></day-card>
    <day-list :data='dayData'></day-list>
  </div>
</template>

<script>
import getData from '@/services'
import { getNowDate } from '@/libs/utils'
import { computed, onMounted } from 'vue'
import { useStore } from 'vuex'

import DayCard from '@/components/DayPage/Card'
import DayList from '@/components/DayPage/List'

export default {
  name: 'DayPage',
  components: { DayCard,DayList },
  setup() {
    const store = useStore(),
      state = store.state

    onMounted(() => {
      // getData(store, 'day', getNowDate('day'))
    })

    return {
      dayData: computed(()=> state.dayData)
    }
  },
}
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值