need Use Vue to collect user data like this: Get data and submitCode implementation: Bind the value of value to the variable attribute <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Get form data</title> <script src="/static/js/vue.js"></script> </head> <body> <div id="container"> <form action="" @submit.prevent="submit"> <label for="username">Username:</label><br> <input type="text" class="username" name="username" placeholder="Enter username" v-model.lazy="user.username"><br> <label for="password">Password:</label><br> <input type="password" class='password' name="password" placeholder="Enter password" v-model="user.password"><br> <label for="age">Age:</label><br> <!-- type is number, only numbers are allowed; input is also a string --> <!-- v-model.number, convert the input string into a numerical value --> <input type="number" name="age" v-model.number="user.age"><br> <label for="">Gender:</label> <!-- Abnormal input --> <input type="radio" name="sex" v-model="user.sex" value="female">Female<input type="radio" name="sex" v-model="user.sex" value="male">Male<br> <!-- Multiple Selection --> <label for="">Hobbies:</label> <input type="checkbox" v-model="user.hobby" value="pingpong">Table tennis<input type="checkbox" v-model="user.hobby" value="basketball">Basketball<input type="checkbox" v-model="user.hobby" value="football">Soccer<br> <!-- Drop-down selection box--> <span>Select City:</span><br> <select name="city" v-model="user.city" id=""> <option value="">Select a city</option> <option value="zz">Zhengzhou</option> <option value="wh">Wuhan</option> <option value="bj">Beijing</option> </select> <br> <!-- Text box --> <label for="">Description:</label><br> <textarea name="desc" v-model="user.desc"></textarea> <br> <!-- Protocol --> <input type="checkbox" name="agree" v-model="user.agree">Read and accept the <a href="http://www.baidu.com">User Agreement</a> <!-- Click the button to submit--> <button :style="{display:'block',backgroundColor:'lightblue',}">Submit</button> <!-- submit --> <!-- <input type="submit" value="Submit"> --> </form> </div> <script> Vue.config.productionTip = false new Vue({ el: "#container", data: { user: { username: "", password: "", age: "", sex: "", hobby: [], city: "", desc: "", agree: "", } }, methods: { submit(event){ console.log("Submit the form") // In the form, the parameters are automatically submitted console.log(JSON.stringify(this.user)) }, }, }) </script> </body> </html> Template Filters<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Template Filter</title> <script src="/static/js/vue.js"></script> <script src="/static/js/dayjs.min.js"></script> </head> <body> <div id="container"> <!-- Filters --> <span>{{ time | timeFormatter}}</span><br> <!-- The first parameter of the parameter-passing filter is always the pipeline data--> <span>{{ time | timeFormatter("YY-MM-DD hh:mm:ss")}} </span> <!--Multiple filters can also be connected in series--> </div> <script> Vue.config.productionTip = false //Global filter, available in all components Vue.filter("myFilter", function(value){ return 'global filtering' }) new Vue({ el: "#container", data: { time: 1639579694662, //timestamp, not a string}, //Local filter, used inside the component filters: { timeFormatter(time, format){ // The first parameter if (format) { return dayjs(time).format(format) }else{ return dayjs(time).format("YYYY-MM-DD HH:mm:ss") } }, }, }) </script> </body> </html> Filter usage scenarios1. Used in interpolation syntax 2. Processing some simple operations generates new data SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: Example of using CSS3 to create Pikachu animated wallpaper
>>: Tutorial on using the hyperlink tag in HTML
This article is based on Linux centos8 to install...
The following are all performed on my virtual mac...
1. Table structure 2. Table data 3. The query tea...
This article shares the specific code of JavaScri...
Preface When sharing a page, you hope to click th...
Table of contents Preface Several common bit oper...
Preface To modify file permissions in the termina...
This should be something that many people have do...
Install virtualization software Before installing...
The so-called connection limit in Nginx is actual...
Table of contents Docker deployment Always on clu...
This article example shares the specific code of ...
Recently, I need to make a back-to-top button whe...
Since the problem occurred rather suddenly and th...
This article introduces RHEL8 network services an...