我和前辈妥协了。
我尝试了两个不同的结果。
一种方式)
通过python从数据库收集数据——mysqlClient连接
前端
axios.get("url/")
.then((res) => {
if (res.data.status === 200) {
data_table_HDR = res.data.HDR
data_table_body = res.data.body
}
}).catch((err)=>{console.log(err)})
后台
connection = mysqldb.connectoin(connection_info ID,PW,HOST,PORT etc..)
cursor = connection.cursor()
cursor.excute(f"select * from certain_table")
data = cursor.fetchall()
resp_data = {HDR: data[0], body: data[1]}
response(data=data, status=200)
以这种方式,嗯...浏览器的屏幕是白色的“无响应”并且无法正常工作,因此不得不通过窗口的系统管理来终止该进程。
还有我使用pycharm IDE的python IDE,它没有像没有响应一样正常工作,所以我也不得不杀死它。
我向他展示了这种症状(现象)然后令人惊讶的是他的反应有点高兴。
然后他建议如下其他方式,我称之为“B方式”。
B方式)
前端
const isInit = False
do_data_collect() {
if (isInit === False) {
this.init()
} else {
this.nextStep(user_input_integer)
}
}
init(user_input_integer) {
limit_value = user_input_integer
axios.get("url/" + limit_value)
.then((res) => {
if (res.data.status === 200) {
data_table_HDR = res.data.HDR
data_table_body = res.data.body
isInit = True
}
}).catch((err)=>{console.log(err)})
}
nextStep(user_input_integer) {
limit_value = user_input_integer
offset = limit_value + limit_value
axios.get({
url: "url",
method: "GET",
headers: {
token
},
params: {
limit_value: limit_value,
offset: offset
})
.then((res) => {
if (res.data.status === 200) {
data_table_body.append(res.data.body)
}
}).catch((err)=>{console.log(err)})
}
后台
limit_value = request.get("limit_value")
offset = request.get("offset")
connection = mysqldb.connectoin(connection_info ID,PW,HOST,PORT etc..)
cursor = connection.cursor()
cursor.excute(f"select * from certain_table limit {limit_value} offset {offset}")
data = cursor.fetchall()
resp_data = {HDR: data[0], body: data[1]}
response(data=data, status=200)
以这种B方式,
它像乒乓球一样工作。
具有数量限制和偏移的前端请求。
后端执行读取文件或从数据库获取数据。
前端收到响应并将其结果显示为弹出窗口(对话框)以及当用户
通过鼠标向下滚动,然后 API 再次出现并循环,直到不再出现
数据。
这样,就没有浏览器和 IDE 宕机的问题了。
但是,data_table_body 会附加下一个包含大量数据的数据
以免出现内存问题。
因此,将海量数据的所有数据显示给最终用户并不是一个好主意。
我认为将数据作为文件下载会更好。
我也在吗?在这个世界上演这部工作剧?
实施、测试和比较......每次...... :(