[英]Vue js submit function
There is code to handle the button to close the page and initialize submit有代码处理按钮关闭页面和初始化提交
window.onbeforeunload = function(e) {
var dialogText = 'Dialog text here';
e.returnValue = dialogText;
return dialogText;
};
How to use JavaScript to process this function in Vue JS to send the form through HTML tags?如何在Vue JS中使用JavaScript处理这个函数通过HTML标签发送表单? I did similar things on Jinja, but I can specify data directly in the URL我在 Jinja 上做了类似的事情,但是我可以直接在 URL 中指定数据
You need to bind that function to the beforeunload
window event when the component is initialized.您需要在组件初始化时将该函数绑定到beforeunload
窗口事件。
Example:例子:
mounted() {
window.addEventListener("beforeunload", this.unload);
},
methods: {
unload(e) {
var dialogText = 'Dialog text here';
e.returnValue = dialogText;
return dialogText;
}
}
Alternatively, if you're using the form
element with a submit function, you could just call unload()
directly?或者,如果您使用带有提交功能的form
元素,您可以直接调用unload()
吗? Hard to know whether that would simplify the solution without seeing more of your code.很难知道这是否会在没有看到更多代码的情况下简化解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.