-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
100 lines (94 loc) · 3.46 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>5分钟开发一个行情软件</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<style>
html {
font-family: Roboto-medium, Roboto, PingFangSC-Medium, Microsoft YaHei;
}
.blue {
color: #008555;
}
.red {
color: #d60f2a;
}
</style>
</head>
<body>
<div id="app" v-loading="loading">
<h1 style="text-align: center">5分钟开发一个行情软件</h1>
<el-table :data="tableData" style="width: 100%">
<el-table-column prop="rank" width="60" label="#" sortable></el-table-column>
<el-table-column prop="symbol" label="币种" align="center" sortable></el-table-column>
<el-table-column prop="market_cap_usd" label="流通市值($)" align="right" sortable>
<template slot-scope="scope">{{scope.row.market_cap_usd | handleBigNumber}}</template>
</el-table-column>
<el-table-column prop="price_usd" label="全球指数($)" align="center" sortable>
<template slot-scope="scope">
<span :class="scope.row.percent_change_1h > 0 ? 'blue' : 'red'">{{scope.row.price_usd}}</span>
</template>
</el-table-column>
<el-table-column prop="volume_24h_usd" label="24H额($)" align="right" sortable>
<template slot-scope="scope">{{scope.row.volume_24h_usd | handleBigNumber}}</template>
</el-table-column>
<el-table-column prop="market_cap_usd" label="流通数量" align="right" sortable>
<template slot-scope="scope">{{scope.row.market_cap_usd | handleBigNumber}}</template>
</el-table-column>
<el-table-column prop="percent_change_24h" label="24H涨幅" align="center" sortable>
<template slot-scope="scope">
<span :class="scope.row.percent_change_24h > 0 ? 'blue' : 'red'">{{scope.row.percent_change_24h + '%'}}</span>
</template>
</el-table-column>
</el-table>
</div>
<script>
var app = new Vue({ // Vue实例 动态绑定数据
el: '#app',
data() {
return {
tableData: [],
timer: null,
loading: false
}
},
mounted() {
updateDataTimer.call(this);
},
filters: {
handleBigNumber(usd) {
if (usd > 1e12) return (usd / 1e12).toFixed(2) + '万亿'
if (usd > 1e8) return (usd / 1e8).toFixed(2) + '亿'
if (usd > 1e4) return (usd / 1e4).toFixed(2) + '万'
return usd
}
},
destroyed() {
clearInterval(this.timer);
this.timer = null;
}
});
function updateDataTimer() { // 设计一个定时器,不停的去更新数据
getExchangeInfo.call(this);
}
async function getExchangeInfo() { // 获取交易所的数据
if (this.tableData.length === 0) this.loading = true
try {
const { data } = await axios.get(`https://ticker.liuzemei.com/`)
this.tableData = data
if (this.loading) this.loading = false
} catch (e) {
this.$message.error('加载失败...正在重试...')
return getExchangeInfo.call(this)
}
this.timer = setTimeout(getExchangeInfo.bind(this), 60 * 1000)
}
</script>
</body>
</html>