Files
DDDMicroFrontend/front-end/main-app/src/app/views/Home.tsx
2025-09-17 21:59:50 +08:00

65 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineComponent, reactive, onMounted } from 'vue'
import Header from '@/components/Header'
import { HttpConfig } from '@shared/config/index'
import { UrlCheckUtils } from '@shared/utils'
import { useCounterStore } from '@/stores/counter'
import { storeToRefs } from 'pinia'
interface stateType {
list: ListItemType[]
}
interface ListItemType {
id: number
title: string
}
export default defineComponent({
name: "Home",
setup() {
const counterStore = useCounterStore()
const { increment } = counterStore
const { count, doubleCount } = storeToRefs(counterStore)
const state = reactive<stateType>({
list: [
{ id: 1, title: '新闻1' },
{ id: 2, title: '新闻2' },
{ id: 3, title: '新闻3' },
]
})
onMounted(() => {
// console.log("onMounted: ", HttpConfig.DevBaseUrl);
console.log("check: ", UrlCheckUtils.check())
})
// 定义处理子组件事件的函数
const handleChildEvent = (message: string) => {
console.log('收到子组件事件:', message)
}
return () => (
<div class="home">
<Header
text={state.list}
onClick={() => {
console.log("通过props自定义事件传给子组件");
}}
onSendMessage={handleChildEvent}>
{{
scoped: (item: ListItemType) => <li key={item.id}>{item.title}</li>,
header: () => <div class="header"> </div>,
default: () => <div class="default"> default </div>
}}
</Header>
<h1></h1>
<div class="count" onClick={increment}>+1{count.value}</div>
</div>
)
}
})