javascript - 重定向后如何显示警报指示器?
解决方案
我相信您可以在烧瓶中创建一个重定向并设置 cookie 的响应。就像是
from flask import make_response
response = make_response(redirect('/homepage'))
response.set_cookie('show_success_flash', 'true')
return response
然后,在您的 JS 端,您可以读取 cookie,如果它是真的,则显示消息。然后,您可以在关闭 flash 消息时删除 cookie,也可以在 setTimeout 后将其删除。就像是:
// homepage.js
const cookie = import 'js-cookie'
if (cookie.get('show_success_flash') {
const successFlash = document.getElementById('success_flash_message')
if (successFlash.style.display === 'none') {
successFlash.style.display = 'block'
}
}
推荐阅读
- python - 设置matplotlib表的行边缘颜色
- excel - 在 SrchRng 中,如果单元格包含数据,则将公式粘贴到右侧
- haskell - haskell 源代码中的内联函数
- git - 如何合并两个分支而不丢失另一个不包含的文件?
- javascript - 当 jquery 在该字段中插入变量时,如何检查输入字段是否为空?
- python - Python:在 API 中放置配置文件的位置
- reactjs - 使用 React 绑定两个输入文本
- ios - 集合视图中行和列之间的意外空格
- java - Java中数组的总和
- tensorflow - 是否可以将已经训练好的 Keras 部署到 Sagemaker?