This article example shares the specific code of Vue to implement form validation for your reference. The specific content is as follows 1. Route jumpFirst, open the src directory in the Vue project to configure the router file, then use import to expose your form page name and register the routing table in your Router instance. The code is as follows import Create from "@/views/create/create.vue"; //The first letter of the exposed name should be capitalized. The following is the directory where your form page is located @ is the abbreviation of .., which means returning to the previous level const router = new Router ({ mode:"history"//This is the route mode. routes:[ { path: "/create", //Default is /. If there are multiple paths, it is / plus the path name: "create", component: Create, title: "Form", }, ] }) After the routing table is configured, remember to configure the to option of your router-link tag in the home page. <router-link :to="{ name: 'create' }" class="collection">Form</router-link> Then the form page Rendering The function implementation code is as follows The plugin uses element.ui. You can use npm i element-ui in the terminal. After successful installation, check it in package.json and reference it in main.js After the installation is complete, you can use it. <template> <div class="create"> <h2>Welcome to publish a new recipe, please introduce your masterpiece first! </h2> <section class="create-introduce"> <h5>Title</h5> <el-input v-model="backData.title" class="create-input" placeholder="Please enter content" ></el-input> <h5>Attributes</h5> <div> <el-select v-for="item in propertyies" :key="item.parent_name" :placeholder="item.parent_name" v-model="backData.property[item.title]" > <el-option v-for="option in item.list" :key="option.type" :label="option.name" :value="option.type" > </el-option> </el-select> </div> <h5>Recipe Categories</h5> <div> <el-select placeholder="Please select the recipe category" v-model="backData.classify"> <el-option-group v-for="group in classifies" :key="group.parent_type" :label="group.parent_name" > <el-option v-for="item in group.list" :key="item.type" :label="item.name" :value="item.type" > </el-option> </el-option-group> </el-select> </div> <h5>Finished product picture (328*440)</h5> <div class="upload-img-box clearfix"> <div class="upload-img"> <upload-img action="/api/upload?type=product" :img-url="backData.product_pic_url" @res-url=" (data) => { backData, (product_pic_url = data.res); } " ></upload-img> </div> <el-input class="introduce-text" type="textarea" :rows="10" placeholder="Please enter content" > </el-input> </div> </section> <h2>Record all raw materials</h2> <section class="create-introduce"> <h5>Main ingredients</h5> <!--[ { "name": "", "specs": "" }, { "name": "", "specs": "" }, { "name": "", "specs": "" } ]--> <Stuff v-model="backData.raw_material.main_material"></Stuff> <h5>Accessories</h5> <Stuff v-model="backData.raw_material.accessories_material"></Stuff> </section> <h2>Start writing the steps! Whether it is easy to learn depends on how you write it. Good luck! </h2> <section class="create-introduce"> <Upload v-for="(item, index) in 3" :key="index"></Upload> <el-button class="eaeaea add-step-button" type="primary" size="medium" icon="el-icon-plus" @click="add" >Add one step</el-button > <h5>Cooking tips</h5> <el-input class="introduce-text" type="textarea" :rows="8" placeholder="Share your experience and tips in making this dish!" > </el-input> </section> <el-button class="send" type="primary" size="medium" :icon="icon" >Done, submit for review</el-button > </div> </template> <script> import Stuff from "./stuff"; import Upload from "./step-upload"; import UploadImg from "@/components/upload-img"; import { getProperty, getClassify, publish } from "@/service/api"; const raw_materia_struct = { name: "", specs: "", }; export default { name: "create", components: { Stuff, Upload, UploadImg }, data() { return { backData: { title: "", property: {}, classify: "", product_pic_url: "", product_story: "", raw_material: { raw_material: Array(3) .fill(1) .map(() => ({ ...raw_materia_struct })), accessories_material: Array(3) .fill(1) .map(() => ({ ...raw_materia_struct })), }, }, propertyies: [], classifies: [], }; }, mounted() { getProperty().then(({ data }) => { console.log(data); this.propertyies = data; this.backData.property = data.reduce((o, item) => { o[item.title] = ""; return o; }, {}); // console.log(data); // console.log(this.backData.property) }); getClassify().then(({ data }) => { console.log(data); this.classifies = data; }); }, methods: { add() { console.log(1); }, }, }; </script> <style lang="stylus"> .create-introduce background-color #fff padding 20px .add-step-button margin-left 100px .create width 100% h2 text-align center margin 20px 0 .send // ff3232() height: 70px; width: 220px; background #ff3232 color #fff border none margin 20px auto display block h5 margin 20px 0 .create-input input width 446px line-height 22px .upload-img-box .upload-img float left .introduce-text float left .el-textarea width 60% margin-left 10px </style> The above is all about the Vue form. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to deploy a simple c/c++ program using docker
>>: mysql implements importing only a specified table from the sql file of exported data
The Docker publishing method provides many conven...
Table of contents 1. Pull the image 2. Create a R...
1. Go to the official website www.mysql.com and s...
Table of contents 【Code background】 【Code Impleme...
1. Add PRIMARY KEY (primary key index) mysql>A...
Chinese Tutorial https://www.ncnynl.com/category/...
Sometimes, we need to copy a whole column of data...
This article example shares the specific code of ...
This article shares the specific code of JavaScri...
Preface: The MySQL database provides a wide range...
How to shorten the page rendering time on the bro...
Today, there is such a requirement. If the logged...
Table of contents Before transformation: After tr...
First, let's talk about why we use provide/in...
The transaction log records the operations on the...