当前位置:网站首页>第十三届蓝桥杯(Web 应用开发)线上模拟赛【第九题】(知乎首页数据动态化)
第十三届蓝桥杯(Web 应用开发)线上模拟赛【第九题】(知乎首页数据动态化)
2022-08-08 20:32:00 【左手】
第十三届蓝桥杯(Web 应用开发)线上模拟赛参考答案全集
考试需求
通过 axios 请求知乎首页文章列表数据并绑定到 List.vue 组件。 API 接口地址 文章列表 public/static/data/list.json 接口响应示例 首页布局样式与效果图保持一致。
解决办法
在list.vue文件中先用axios请求请求加载json文件,前端用vue的v-for语句和v-bind进行渲染(初始化请求接口用create方法)
参考代码
先在main.js中引入axios
main.js
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
router,
render: function(h) { return h(App) }
}).$mount('#app')
再进行axios操作和v-for遍历
./src/components/list.vue
<template>
<div class="list">
<div
class="list-item"
v-for="item in dataList"
>
<img
class='list-pic'
:src="item.imgUrl"
/>
<div class="list-info">
<p class='title'>{{ item.title }}</p>
<p class='desc'>{{ item.desc }}</p>
</div>
</div>
</div>
</template>
<script>
export default {
created(){
// 页面初始化,用于请求数据
this.$axios.get('./static/data/list.json').then(res=>{
this.dataList = res.data.data.listInfo;
})
},
data() {
return {
dataList: []
};
}
};
</script>
<style scoped>
.list-item {
padding: 20px 0;
overflow: hidden;
border-bottom: 1px solid #dcdcdc;
}
.list-pic {
float: right;
width: 125px;
height: 100px;
display: block;
border-radius: 4px;
}
.list-info {
width: 500px;
float: left;
}
.title {
padding: 10px 0;
font-size: 18px;
font-weight: bold;
color: #333;
}
.desc {
line-height: 22px;
font-size: 13px;
color: #999;
}
</style>
边栏推荐
猜你喜欢
莅临GOPS大会龙智展位,获取Forrester最新报告:《Forrester Wave:2021年第四季度企业服务管理报告》
内网渗透之代理转发
From interview to autism, five rounds of interviews for byte software testing post, four hours of soul torture...
书法家唐效奇
学习与尝试 --> 事件风暴
学习笔记:2.3 静态链表 循环链表 双向链表
C语言关键字入门 这一篇足矣
接口测试经典面试题:Session、cookie、token有什么区别?
劳务派遣业务流程图
Ansible自动化运维工具(一)安装及模块
随机推荐
随手记:laravel、updateOrCreate 和 updateOrInsert 的区别
五大理由告诉你为什么开发人员选择代码质量静态分析工具Klocwork来实现软件安全
书法家唐效奇
What are the role of document management system for companies?
学习笔记:2.3 静态链表 循环链表 双向链表
C语言初阶-指针
门外汉掌握数据分析处理技术的路线图
Kotlin reflection
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
【翻译】宣布Kubernetes策略管理论文
Kotlin解析String路径小知识
How can recommender systems be trusted?A review of the latest "Trusted Recommender System" from Rutgers University, a 43-page pdf explaining the composition and technology of trusted RS
借问变量何处存,牧童笑称用指针,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang类型指针(Pointer)的使用EP05
学习笔记:第二部分 队列
LeetCode_67_二进制求和
What are the latest developments in the handling of false information?KDD2022 "Fighting Misinformation and Responding to Media Bias" tutorial, 161 pages ppt
Mendix:企业成功执行数字化转型的9个因素
【无标题】
MySQL权限管理
使用fontforge修改字体,只保留数字