|- book.vue // 图书展示页面 |-- BookList.vue // 图书列列表组件
// 引入组件
import BookList from '../../components/bookList/BookList.vue';
// 注册组件
components:{
BookList,
},
// 使用组件
<book-list></book-list>
|- book.vue - html 页面
<template>
<div>
<h2>欢迎来到波波图书馆!</h2>
<!-- 推荐读书 -->
<section class="box recommend-book">
<!-- 大家注意 :books 是BookList.vue组件里图书对象数组 heading 是传给组件的标题 -->
<book-list :books="recommendArray" heading="推荐图书"></book-list>
</section>
<!-- 最新图书 -->
<section class="box update-book">
<!-- 大家注意 :books 是BookList.vue组件里图书对象数组 heading 是传给组件的标题 -->
<book-list :books="updateBookArray" heading="最新图书"></book-list>
</section>
</div>
</template>
|- book.vue - js
<script>
import BookList from '../../components/bookList/BookList.vue';
export default({
data(){
return {
// 推荐图书
recommendArray:[
{
id:1,
img_url: 'https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=671627465,1455045194&fm=173&s=23A2F3039C930EC41A2DB9090300D093&w=640&h=427&img.JPEG',
book_name:'Vuejs-1',
book_author:'liangfengbo',
},
{
id:2,
img_url: 'https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=671627465,1455045194&fm=173&s=23A2F3039C930EC41A2DB9090300D093&w=640&h=427&img.JPEG',
book_name:'Vuejs-2',
book_author:'liangfengbo',
},
{
id:3,
img_url: 'https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=671627465,1455045194&fm=173&s=23A2F3039C930EC41A2DB9090300D093&w=640&h=427&img.JPEG',
book_name:'Vuejs-3',
book_author:'liangfengbo',
},
],
// 最新图书
updateBookArray:[
{
id:5,
img_url: 'https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=671627465,1455045194&fm=173&s=23A2F3039C930EC41A2DB9090300D093&w=640&h=427&img.JPEG',
book_name:'Vuejs-5',
book_author:'liangfengbo',
},
{
id:6,
img_url: 'https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=671627465,1455045194&fm=173&s=23A2F3039C930EC41A2DB9090300D093&w=640&h=427&img.JPEG',
book_name:'Vuejs-6',
book_author:'liangfengbo',
},
{
id:7,
img_url: 'https://ss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=671627465,1455045194&fm=173&s=23A2F3039C930EC41A2DB9090300D093&w=640&h=427&img.JPEG',
book_name:'Vuejs-7',
book_author:'liangfengbo',
},
],
}
},
// 引入组件
components:{
BookList,
},
methods : {
},
})
</script>
|- book.vue - css
<style>
*{
margin: 0;
padding: 0;
}
li{
list-style:none;
}
.box{
height: auto;
border-bottom: 1px solid #efefef;
margin: 10px 0;
padding: 5px 0;
}
</style>
|- 组件 - BookList.vue - html
<template>
<div>
<!-- 头部 -->
<!--这个是页面传来的标题 -->
<h3 class="heading">{{heading}}</h3>
<!-- 列表 -->
<article class="book-list">
<!-- 遍历图书数据 -->
<li v-for="book in books">
<router-link :to="{ name:'BookDetail',params:{ id: book.id }}">
 <!-- 图书图片 -->
{{book.book_name}} <!-- 图书名字 -->
</router-link>
</li>
</article>
</div>
</template>
<script>
export default({
// props 数据传递的意思
props:[
'heading',//标题
'books',//图书对象数组
],
data(){
return {
}
},
methods : {
},
})
</script>
<style scoped>
/*图书列表*/
.book-list {
width:100%;
height:128px;
display: flex;
justify-content: space-around;
}
.heading {
border-left: 4px solid #333;
margin: 10px 0;
padding-left: 4px;
}
.book-list li {
width:80px;
height: 100%;
flex:1;
margin:0 10px;
}
.book-list li img{
height: 100px;
width: 100%;
}
.book-list li a{
text-align: center;
font-size: 12px;
text-decoration: none;
display: inline-block;
width: 100%;
}
</style>
<start-set-timeout seconds=60 ref="contTimer"></start-set-timeout>
// 调用时加一个定时器
setTimeout(() => {
this.$refs.contTimer.countTime(60)
}, 20)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有