vue 侦听器侦听对象属性
Unfortunately for me, web forms a big part of my day. It's not that web forms are difficult, it's that they're so damn time consuming. Validation, formatting, and processing are a must for web forms and the redundancy that goes into performing the task over and over is enough to drive a developer crazy.
对我来说不幸的是,网络是我一天中很重要的一部分。 并不是说网络表单很困难,而是因为它们是如此的耗时。 验证,格式化和处理是Web表单所必需的,一遍又一遍地执行任务所需要的冗余足以使开发人员发疯。
The trigger to the form validation and subsequent processing is form submission. How do you know when a form has been submitted? At the top of the PHP script, before any output, you code:
表单验证和后续处理的触发因素是表单提交。 您如何知道何时提交表单? 在PHP脚本的顶部,在进行任何输出之前,您需要编写以下代码:
if(isset($_POST['submit'])) { //validation here //conditional processing here}
What if there's also a "cancel" button? You'd code:
如果还有一个“取消”按钮怎么办? 您将代码:
if(isset($_POST['submit'])) { //validation here //conditional processing here}elseif(isset($_POST['cancel'])) { //redirect somewhere<}
The above isn't good enough for me. I create too many forms to continue the isset() muck. Also, what about the "_x" browser quirk for when you have an image submit button (e.g. instead of PHP reading in "submit", it reads in "submit_x")? What about maintainability? I've created a function to handle all form submission situations that works great for my purposes.
以上对我来说还不够好。 我创建了太多表格,无法继续isset()废话。 另外,当您有图像提交按钮时,“ _ x”浏览器会有什么古怪之处(例如,不是在“ submit”中读取PHP,而是在“ submit_x”中读取)? 可维护性如何? 我创建了一个功能来处理所有表单提交情况,这些功能非常适合我的目的。
代码 (The Code)
function submit($trigger = 'submit') { return (isset($_POST[$trigger]) || isset($_POST[$trigger.'_x']) || isset($_GET[$trigger]) || isset($_GET[$trigger.'_x']));}
用法 (The Usage)
if(submit()) { //submit button pressed}elseif(submit('cancel')) { //cancel button pressed}
说明 (The Explanation)
There's one optional argument to send to the function: $trigger. $trigger represents the name of the button you expect to be pressed -- default being "submit." If one of the buttons is pressed, the selected processing is run; if not, no processing is run.
有一个可选的参数发送给函数: $ trigger 。 $ trigger表示您希望按下的按钮的名称-默认为“提交”。 如果按下其中一个按钮,则运行所选的处理; 如果不是,则不运行任何处理。
Do you have a function you use? If so, please share.
您有使用的功能吗? 如果是这样,请分享。
翻译自:
vue 侦听器侦听对象属性