feat: 增加新闻页

This commit is contained in:
xiongxiaoyang
2022-05-16 14:40:26 +08:00
parent 3fc8486c6a
commit 364c4fd489
5 changed files with 79 additions and 10 deletions

View File

@@ -9,6 +9,7 @@
type="text"
placeholder="书名、作者、关键字"
class="s_int"
v-on:keyup.enter="searchByK"
/>
<label class="search_btn" id="btnSearch" @click="searchByK()"
><i class="icon"></i

View File

@@ -2,24 +2,25 @@
<dl class="hot_notice" id="indexNews">
<dd style="text-align: left" v-for="(item, index) in newsList" :key="index">
<span>[{{ item.categoryName }}]</span>
<router-link :to="{ name: 'newsContent', query: { id: item.id } }">
{{ item.title }}
</router-link>
<a href="javascript:void(0)" @click="newsInfo(item.id)"> {{ item.title }}</a>
</dd>
</dl>
</template>
<script>
import { reactive, toRefs, onMounted } from "vue";
import { useRouter, useRoute } from "vue-router";
import { ElMessage, ElLoading } from "element-plus";
import {listLatestNews} from "@/api/news";
import { listLatestNews } from "@/api/news";
export default {
name: "LatestNews",
setup() {
const state = reactive({
newsList: [],
});
const route = useRoute();
const router = useRouter();
onMounted(async () => {
const loadingInstance = ElLoading.service({
target: "#indexNews",
@@ -30,9 +31,12 @@ export default {
state.newsList = data;
});
const newsInfo = (newsId) => {
router.push({ path: `/news/${newsId}` });
};
return {
...toRefs(state),
newsInfo,
};
},
};