js实现城市广场查询及渲染axios(需axios.min.js)

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Document</title>

<link rel="stylesheet" href="css/bootstrap.min.css">

<style>

.nav{

display: flex;

margin: 20px;

}

.nav .form-control{

width: 300px;

}

.nav .btn{

width: 80px;

height: 40px;

margin-left: 10px;

}

#btn{

margin: 20px;

}

.card{

margin: 20px;

padding: 10px;

float: left;

height: 430px;

}

.card img{

height: 230px;

}

.card h5{

font-weight: normal;

font-size: 16px;

}

.card .card-text{

color: red;

}

.hide{

/* 英文换行 */

word-break: break-all;

/* 溢出隐藏 */

overflow: hidden;

/* 弹性盒兼容写法 */

display: -webkit-box;

/* 出现几行省略号 */

-webkit-line-clamp: 2;

/* 行与行之间是垂直排列的 */

-webkit-box-orient: vertical;

}

</style>

</head>

<body>

<div class="nav">

<input type="text" class="form-control" autocomplete="off">

<button type="button" class="btn btn-primary">查询</button>

</div>

<div class="active"></div>

<script src="./js/axios.min.js"></script>

<script>

const txt = document.querySelector('input')

const btn = document.querySelector('button')

var active=document.querySelector('.active')

btn.onclick = ()=>{

axios.get('https://jx.xuzhixiang.top/ap/api/search.php', {

params: {

keywords: txt.value.trim()

}

})

.then(res=>{

active.innerHTML=''

console.log(res.data)

const { pois } = res.data

console.log(pois)

pois.forEach(item=>{

if(item.photos.length==0){

console.log(123)

}

else{

active.innerHTML += `

<div class="card" style="width: 18rem;">

<img src="${item.photos[0].url}" class="card-img-top" alt="...">

<div class="card-body">

<h5 class="card-title hide">${item.address}</h5>

<p class="card-text">${item.adname}</p>

</div>

</div>

`

}

})

})

}

</script>

</body>

</html>

相关推荐
Mr_Xuhhh1 天前
YAML相关
开发语言·python
咖啡の猫1 天前
Python中的变量与数据类型
开发语言·python
前端达人1 天前
你的App消息推送为什么石沉大海?看Service Worker源码我终于懂了
java·开发语言
汤姆yu1 天前
基于springboot的电子政务服务管理系统
开发语言·python
云中飞鸿1 天前
函数:委托
javascript
全栈师1 天前
C#中控制权限的逻辑写法
开发语言·c#
S***q1921 天前
Rust在系统工具中的内存安全给代码上了三道保险锁。但正是这种“编译期的严苛”,换来了运行时的安心。比如这段代码:
开发语言·后端·rust
打点计时器1 天前
matlab 解决wfdb工具使用本地数据集报错
开发语言·matlab
zmzb01031 天前
C++课后习题训练记录Day38
开发语言·c++
夏霞1 天前
c# 使用vs code 创建.net8.0以及.net6.0 webApi项目的教程
开发语言·c#·.net