当前位置:网站首页>Edit and preview in the back pipe to get the value writing method of the form
Edit and preview in the back pipe to get the value writing method of the form
2022-07-03 02:58:00 【Scarring body】
Vue Lieutenant general data The value or attribute of an object in is set to null
In the project, we will encounter the problem of initializing data , Sure this.xxx = ‘’, This method is commonly used , But if it is data The data in it , In this way, the code will look redundant .
that , We can use this.assign() Method or Json
// This stupid method But if you need to clear multiple buttons at the same time, you need to write them one by one
data(){
return{
ismenu: {
name: "",
sex: '',
age: '',
birth: "",
address: "",
},
}
}
// Empty ismenu Data value
PS Preview and edit share the same pop-up layer when adding back pipe After the preview is added
Adding and editing data will also be automatically added , At this time, we need to add the situation data when the Edit button is clicked
The general stupid way is this But it's too redundant Don't have to
this.ismenu.name = "";
this.ismenu.sex = "";
this.ismen.age= "";
this.ismenu. birth= "";
this.ismenu.address = "";
this.assign() Method
// Initialize all data data
Object.assign(this.$data, this.$options.data())
// initialization data One of the data
Object.assign(this.$data.xxx, this.$options.data().xxx)
PS You have to empty it alone ismen The value of the object needs
Object.assign(this.$data.ismen, this.$options.data().ismen)
Json
Json First in data In the definition of xxx:[{
a:1}], stay methods Method in Empty data ( initialization )
this.xxx = JSON.parse(JSON.stringify(this.xxx))
See code cloud code for details Quite understand
Get the value of the form
Generally speaking, you will get the value during editing and assign the value
//slot-scope="scope" This is elem The method given by the framework
// scope.$index Get index value , scope.row Get the corresponding value
<template slot-scope="scope">
<el-button
size="mini"
style="margin: 0"
@click.stop="btnedit(scope.$index, scope.row)"> edit </el-button>
</template>
// This is to get the corresponding value
// Then click Print to see the method inside
btnedit(index,scope){
console.log(index,scope)// Print the obtained value
}
And while you are editing , You need to get the corresponding value in the form, such as this
<el-form :model="ismenu" ref="ismenu" :rules="editFormRules">
<!-- full name Gender Age Birthday Address -->
<el-form-item label=" full name " prop="name">
<el-input
style="width: 60%"
v-model="ismenu.name"
autocomplete="off"
:disabled="titleResult[dialogStatus] == ' preview '"
></el-input>
</el-form-item>
<el-form-item label=" Gender " prop="sex">
<el-radio-group
v-model="ismenu.sex"
:disabled="titleResult[dialogStatus] == ' preview '"
>
<el-radio :label="1"> male </el-radio>
<el-radio :label="0"> Woman </el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label=" Age " prop="age">
<el-input-number
v-model="ismenu.age"
:min="0"
:max="200"
:disabled="titleResult[dialogStatus] == ' preview '"
></el-input-number>
</el-form-item>
<el-form-item label=" Birthday " prop="birth">
<el-date-picker
v-model="ismenu.birth"
type="date"
:disabled="titleResult[dialogStatus] == ' preview '"
placeholder=" Select date "
>
</el-date-picker>
</el-form-item>
<el-form-item label=" Address " prop="addr">
<el-input
type="textarea"
style="width: 60%"
v-model="ismenu.addr"
show-word-limit
placeholder=" Please enter the address "
:disabled="titleResult[dialogStatus] == ' preview '"
:maxlength="1024"
></el-input>
</el-form-item>
</el-form>
// so what You have to data It defines your value
ismenu: {
// The form should be consistent with the input parameters required by the back end
name: "",
sex: -1,
age: 0,
birth: "",
addr: "",
},
The most important thing is to come
When you change or add data here
You must get model It's worth it
// Take editors for example
btnedit(index,scope){
this.$nextTick(() => {
// The general assignment is written like this But this is a stupid way
// (this.ismenu.name = scope.name),
// (this.ismenu.sex = scope.sex),
// (this.ismenu.age = scope.age),
// (this.ismenu.birth = scope.birth),
// (this.ismenu.addr = scope.addr);
// You can assign values in this way. You can get them all directly by enumerating
this.ismenu=Object.assign({
}, scope)
}));
}
// Then you add Adding will automatically assign values. At this time, you need
Restore is initialization ismenu Value of form
We usually write like this
// (this.ismenu.name = ''),
// (this.ismenu.sex =''),
// (this.ismenu.age =''),
// (this.ismenu.birth = ''),
// (this.ismenu.addr = '');
Directly
Object.assign(this.$data.ismenu, this.$options.data().ismenu);
This method
// Initialize all data data
Object.assign(this.$data, this.$options.data())
// initialization data One of the data
Object.assign(this.$data.xxx, this.$options.data().xxx)
This is added successfully when adding Prevent the next click to add The last addition is still
this.$refs["ismenu"].resetFields();// Empty the contents of the form In case of the next click, the original data is still
边栏推荐
- 【富瀚6630编码存录像,用rtsp服务器及时间戳同步实现vlc观看录像】
- 从C到Capable-----利用指针作为函数参数求字符串是否为回文字符
- 2022-2028 global splicing display industry research and trend analysis report
- Kubernetes cluster log and efk architecture log scheme
- 力扣------网格中的最小路径代价
- Cron表达式介绍
- HTB-Devel
- Force freeing memory in PHP
- Force deduction ----- the minimum path cost in the grid
- Three.js本地环境搭建
猜你喜欢

TCP 三次握手和四次挥手机制,TCP为什么要三次握手和四次挥手,TCP 连接建立失败处理机制
![[principles of multithreading and high concurrency: 1_cpu multi-level cache model]](/img/c7/6b5ab4ff7379bfccff7cdbb358ff8f.jpg)
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]

用docker 連接mysql的過程

迅雷chrome扩展插件造成服务器返回的数据js解析页面数据异常

Pytest (6) -fixture (Firmware)

Kubernetes cluster log and efk architecture log scheme

HW initial preparation

C language beginner level - pointer explanation - paoding jieniu chapter

Can netstat still play like this?
![[fluent] JSON model conversion (JSON serialization tool | JSON manual serialization | writing dart model classes according to JSON | online automatic conversion of dart classes according to JSON)](/img/6a/ae44ddb090ce6373f04a550a15f973.jpg)
[fluent] JSON model conversion (JSON serialization tool | JSON manual serialization | writing dart model classes according to JSON | online automatic conversion of dart classes according to JSON)
随机推荐
[Fuhan 6630 encodes and stores videos, and uses RTSP server and timestamp synchronization to realize VLC viewing videos]
[fluent] future asynchronous programming (introduction | then method | exception capture | async, await keywords | whencomplete method | timeout method)
力扣------网格中的最小路径代价
[translation] flux is safe. Gain more confidence through fuzzy processing
Sous - système I2C (IV): débogage I2C
The difference between left value and right value in C language
tensor中的append应该如何实现
Matlab tips (24) RBF, GRNN, PNN neural network
内存泄漏工具VLD安装及使用
Kubernetes cluster log and efk architecture log scheme
Use optimization | points that can be optimized in recyclerview
Chart. JS multitooltip tag - chart js multiTooltip labels
Getting started | jetpack hilt dependency injection framework
Wechat - developed by wechat official account Net core access
Global and Chinese ammonium dimolybdate market in-depth analysis and prospect risk prediction report 2022 Edition
ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc
Concrete CMS vulnerability
HW-初始准备
Update and return document in mongodb - update and return document in mongodb
超好用的日志库 logzero