“希望你喜欢我的内容,记得关注我哦!我会继续为大家带来更好的作品!”
1、这里讲一下home网页的布局,到我们的home组件中:
2、home页面就是,这个页面
3、把axios给配置好
4、这里配置好,默认访问的地址
5、这里我们配置一个基本的端口9000,从9000端口进行一个访问
6、我们使用element-ui使用这个走马灯
7、把这里覆盖下来
8、这里调基本样式就可以调
9、我们是用来获取到我们的cat这张图片
10、我们目的就是用来获取到这里的数据
11、用这个接口,来获取接口信息
12、这个请求的基本地址就是拼接到这个地方
13、这里我们可以得到一个res信息
14、在页面创建好的时候,就调用这个函数
15、这里暴露的问题是无法解决跨域问题,一个9000端口,一个8000端口,我们要在前端进行设置,才能够端口中进行访问
16、在util文件夹下创建一个WebConfig来实现一个跨域访问
17、创建好这样一个类
18、我们写好之后,先用@Configuration注解
19、继承一下WebConfi....这个类
20、然后alt + insert重写这个类,重写方法
21、重写这个方法
22、给他设置一下,什么路径允许访问,什么路径不允许访问
23、这句话的意思是我们允许对那个接口进行开放
24、允许什么请求进行访问
25、 允许不允许给个凭证,缓存时间是多少
26、现在我们看到,我们已经获取到了接口信息了
27、你可以把他的数据,放到videoList当中
28、就会获取到这样一些数据
29、使用动态绑定获取信息
30、这里我们需要拼接一下cat的数据信息
31、这里我要拼接一下路径,这里我要获取一个参数
32、获取一个参数
33、这里添加.jpg的URL路径
34、这里我们返回一个URL,给他拼接一下
35、设置一个Style样式
36、我们把他的高度调的高一些
37、这里离图片的高度,还是太高了
38、导致高度太高了,是这里的line-height太高了
39、这里我们设置我们的走马灯的样式
40、刷新一下就变成.....了
41、如果我们想设计成这样的卡片样式
42、样式则要写成这样:
43、样式修改成这样就行了
44、样式写成这样就行了
45、所有卡片都放到中间部分了,而且隔开了
46、style样式设置100%,填充图片
47、homevideo的内容:
<template> <div> <el-carousel :interval="4000" type="card" height="400px"> <el-carousel-item v-for="item in videoList" :key="item.id"> <img :src=getImgURL(item.id) style="width: 100%;height: 100%"> </el-carousel-item> </el-carousel> </div> </template> <script> import axios from "axios"; export default { data(){ return { videoList:[] } }, methods:{ getVideoList(){ axios.get("/videolist").then((res)=>{ this.videoList = res.data console.log(this.videoList) }) }, // getImgURL(imgId){ // return "http://localhost:" // } getImgURL(imgId){ return "http://localhost:9090/static/img/"+ imgId + ".jpg" } }, created(){ this.getVideoList(); } } </script> <style scoped lang="less"> // 走马灯样式 指示器按钮 /deep/ .el-carousel__button { width: 10px; height: 10px; border: none; border-radius: 50%; background-color: rgba(0, 0, 0, 0.2); } // 指示器激活按钮 /deep/ .is-active .el-carousel__button { background: #3f8ec8; } </style>
注意以上的写法是ElementUI的写法,而Elementplus的写法,已经过期了,使用就会产生下面的情况
VideoMainContainer的源码:
<template> <div> <el-carousel :interval="4000" type="card" height="400px" style="margin-bottom: 15px;"> <el-carousel-item v-for="item in videoList" :key="item.id"> <img :src=getImgURL(item.id) style="width: 100%;height: 100%"> </el-carousel-item> </el-carousel> <div style="margin-right: 4%;display: flex;flex-wrap:wrap;align-content:space-between;"> <el-col :span="5" v-for="item in videoList" :key="item.id" :offset="1" style="margin-bottom: 25px;"> <el-card :body-style="{ padding: '0px' }" style="padding-bottom: 17px"> <router-link :to="'/video?video=' + item.id" style="line-height: 0;color: black;text-decoration:none;"> <img :src="getImgURL(item.id)" style="margin-bottom: 7px;"> <!-- <template #footer>{{ item.name }}</template> --> <!-- <p>{{ item.name }}</p> --> <!-- <template #footer>Footer content</template> --> <span style="line-height: 17px;">{{item.name}}</span> </router-link> </el-card> </el-col> </div> <!-- <el-card style="max-width: 480px;max-height: 120px"> <template #header> <div class="card-header"> <span>Card name</span> </div> </template> <p v-for="o in 4" :key="o" class="text item">{{ 'List item ' + o }}</p> <template #footer>Footer content</template> </el-card> --> </div> </template> <script> import axios from "axios"; export default { data(){ return { videoList:[] } }, methods:{ getVideoList(){ axios.get("/videolist").then((res)=>{ this.videoList = res.data console.log(this.videoList) }) }, // getImgURL(imgId){ // return "http://localhost:" // } getImgURL(imgId){ return "http://localhost:9090/static/img/"+ imgId + ".jpg" } }, created(){ this.getVideoList(); } } </script> <style scoped lang="less"> * { margin: 0; padding: 0; } // 走马灯样式 指示器按钮 /deep/ .el-carousel__button { width: 10px; height: 10px; border: none; border-radius: 50%; background-color: rgba(0, 0, 0, 0.2); } // 指示器激活按钮 /deep/ .is-active .el-carousel__button { background: #3f8ec8; } .el-main{ line-height: 0px !important; } </style>
videoMain的源码
<template> <div class="common-layout"> <el-container> <el-header> <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b" style="width: 100%;padding-left: 40px;" :router="true" > <el-menu-item index="/home">首页</el-menu-item> <el-sub-menu index="2"> <template #title>分类</template> <el-menu-item index="2-1">选项1</el-menu-item> <el-menu-item index="2-2">选项2</el-menu-item> <el-menu-item index="2-3">选项3</el-menu-item> <el-sub-menu index="2-4"> <template #title>选项4</template> <el-menu-item index="2-4-1">选项1</el-menu-item> <el-menu-item index="2-4-2">选项2</el-menu-item> <el-menu-item index="2-4-3">选项3</el-menu-item> </el-sub-menu> </el-sub-menu> <el-menu-item index="" style="width: 36%"> <el-input @keydown.enter="mySearch()" placeholder="请输入您想看的视频"> <template #append> <el-button @click="mySearch()">搜索</el-button> </template> </el-input> </el-menu-item> </el-menu> </el-header> <el-main> <router-view></router-view> </el-main> </el-container> </div> </template> <script> export default { data(){ return{ activeIndex: '/home' } }, methods: { mySearch(){ console.log("您已经点击了") } } }; </script> <style scoped lang="less"> * { margin: 0; padding: 0; } .el-header { background-color: #b3c0d1; color: #333; text-align: center; line-height: 60px; } .el-main { background-color: #e9eef3; color: #333; text-align: center; } </style>
最终呈现样式