javascript - 如何在 html 中显示 sql 查询的结果?
问题描述
我想在我的网页中显示 sql 查询的结果。我在服务器端使用 NodeJs,在客户端使用 VueJs。
我查询我的数据库,我得到了这个结果:
[
{
Time_Stamp: 2019-12-09T11:54:00.000Z,
Time_Stamp_ms: 136,
CadenceInstant195: 660,
TempsCycle: 5388,
Totalisateur195: 0,
NCPoste1: 87,
NCPoste2: 2649,
NCPoste4: 503,
NCPoste6: 1821,
NCPoste7: 5590,
EtatMachine: 0
},
{
Time_Stamp: 2019-12-09T11:55:00.000Z,
Time_Stamp_ms: 200,
CadenceInstant195: 660,
TempsCycle: 5395,
Totalisateur195: 0,
NCPoste1: 87,
NCPoste2: 2649,
NCPoste4: 503,
NCPoste6: 1821,
NCPoste7: 5590,
EtatMachine: 0
}
]
这个结果存储在我的 js 文件中的一个变量中,如下所示:
window.onload = function () {
var consultation = new Vue({
el:"#consultation",
data: {
data : []
},
methods: {
load: function() {
this.$http.get("/data?startDate="+this.filtres.startDate+" "+this.filtres.startHour+"&endDate="+this.filtres.endDate+" "+this.filtres.endHour).then(function(response) {
this.data = response.body;
console.log(this.data);
})
}
}
})
}
该函数load()
将查询抛出到数据库。
我的html代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<title>Historique</title>
</head>
<body>
<div id="consultation">
{{todos}}
</div>
<script src='/AffichageHistorique/js/vue.js'></script>
<script src='/AffichageHistorique/js/vue-resource.min.js'></script>
<script src='/AffichageHistorique/js/historique.js'></script>
</body>
</html>
现在我想将查询结果显示到我的网页中,但我不知道如何。当我写入{{data}}
我的 HTML 代码时,它没有显示任何内容。任何想法?
解决方案
您的结果数据为数组格式,您需要循环数据并在 HTML 中绑定。使用 v-for 循环结果数据
<ul id="example-1">
<li v-for="item in items">
{{ item.message }}
</li>
</ul>
var example1 = new Vue({
el: '#example-1',
data: {
items: [
{ message: 'Foo' },
{ message: 'Bar' }
]
}
})
推荐阅读
- css - 我在 F12 开发人员控制台中看到的“normalize.less”是什么?
- javascript - 如何单次搜索来识别一个点值?
- vue.js - 无法在 Ag-grid 中恢复、保存过滤器数据
- python - 从多索引熊猫数据框中选择索引和列的子集
- r - R中从XML到Dataframe的气象数据
- javascript - 性能 - 功能组件内部的功能
- javascript - 如何使用从 SQL 数据库请求的相同数据创建链接?
- android - 将多个事件插入日历非常慢。我可以加快速度吗?
- python - 如何用另一个字典中的键替换字典中的键?
- batch-file - 批量条件连接