News.vue
<template>
<view>
<view v-for="(news, index) in newsList" :key="news.id" @click="navigateToDetail(news)">
{{ news.content }}
</view>
<!-- <view>
<Detail :parent-data = "newslist"></Detail>
</view> -->
</view>
</template>
<script setup lang="ts">
import{reactive} from 'vue'
const newsList = reactive
(
[
{
id:1,content:"清华",time:"1622"
},
{
id:2,content:"北大",time:"1623"
},
{
id:3,content:"北理工",time:"1624"
}
]
)
function switchTabDetail(news: { id: any; content: any; time: any; })
{
uni.switchTab
({
url: `/pages/Detail?id=${news.id}&content=${news.content}&time=${news.time}`
});
}
</script>
Detail.vue
<template>
<view>
<ul class="news-list">
<li>编号:{{id}}</li>
<li>内容:{{content}}</li>
<li>标题:{{time}}</li>
</ul>
</view>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'
const id = ref('')
const content = ref('')
const time = ref('')
onMounted(() =>
{
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const options = currentPage.options;
id.value = options.id;
content.value = options.content;
time.value = options.time;
})
</script>