我的闪烁消息有问题,它运行良好,但现在除了设计之外,我所有的警报/通知都不起作用
我没有在控制台中收到错误,也没有对其进行任何更改 因为它与 Devise 登录/注销一起使用,所以我不知道如何修复它
我尝试过:
binding.pry
=> 工作完成并停止所以我认为我的闪光灯是呼叫,但当它不是来自 Devise 时,屏幕上什么也不会出现
我的闪光灯:
<% if notice %>
<div data-controller="flash" data-flash-text-value="<%= notice %>" data-flash-type-value="success"></div>
<% end %>
<% if alert %>
<div data-controller="flash" data-flash-text-value="<%= alert %>" data-flash-type-value="warning"></div>
<% end %>
我的 flash_controller.js:
import { Controller } from "@hotwired/stimulus"
import Swal from 'sweetalert2'
window.Swal = Swal;
// Connects to data-controller="flash"
export default class extends Controller {
static values = {
text: String,
type: String,
}
connect() {
const Toast = Swal.mixin({
toast: true,
position: 'top-end',
showConfirmButton: false,
showCancelButton: true,
cancelButtonText: 'Fermer',
timer: 6000,
timerProgressBar: true,
didOpen: (toast) => {
toast.addEventListener('mouseenter', Swal.stopTimer)
toast.addEventListener('mouseleave', Swal.resumeTimer)
}
})
Toast.fire({
icon: this.typeValue,
title: this.textValue,
background: "#F1EEFD"
})
}
}
我的application.html.erb
<body>
<% no_promo = current_user || ['devise/registrations', 'devise/sessions'].include?(params[:controller]) %>
<% session_show = params[:action] == 'show' && params[:controller] == 'workshop_sessions' %>
<%= render 'shared/navbar' unless session_show %>
<%= render 'shared/flashes' unless session_show %>
<div class="wrapping-container" style="margin-top: 80px;">
<%= render 'shared/promo' unless no_promo || session_show %>
<%= yield %>
</div>
<%= render 'shared/footer' unless session_show %>
同样的事情也发生在我身上。当我忘记将其写入应用程序的布局文件时
<html>
<body>
.....
<%= render 'sweetify/alert' %>
</body>
</html>
然后重新启动系统对我有用。