当前位置:网站首页>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
边栏推荐
- tensorflow转pytorch笔记;tf.gather_nd(x,y)转pytorch
- JS finds all the parent nodes or child nodes under a node according to the tree structure
- vfork执行时出现Segmentation fault
- [flutter] example of asynchronous programming code between future and futurebuilder (futurebuilder constructor setting | handling flutter Chinese garbled | complete code example)
- Update and return document in mongodb - update and return document in mongodb
- 迅雷chrome扩展插件造成服务器返回的数据js解析页面数据异常
- C语言初阶-指针详解-庖丁解牛篇
- [fluent] futurebuilder asynchronous programming (futurebuilder construction method | asyncsnapshot asynchronous calculation)
- JMeter performance test JDBC request (query database to obtain database data) use "suggestions collection"
- 一文带你了解 ZigBee
猜你喜欢

Add automatic model generation function to hade
![[fluent] listview list (map method description of list set | vertical list | horizontal list | code example)](/img/e5/c01f760b07b495f5b048ea367e0c21.gif)
[fluent] listview list (map method description of list set | vertical list | horizontal list | code example)

What is the way out for children from poor families?

From C to capable -- use the pointer as a function parameter to find out whether the string is a palindrome character

Random shuffle note

力扣------网格中的最小路径代价
![Error when installing MySQL in Linux: starting mysql The server quit without updating PID file ([FAILED]al/mysql/data/l.pid](/img/32/25771baad1ed06c5a592087df748f1.jpg)
Error when installing MySQL in Linux: starting mysql The server quit without updating PID file ([FAILED]al/mysql/data/l.pid

超好用的日志库 logzero

Xiaodi notes

A2L file parsing based on CAN bus (2)
随机推荐
Cancer biopsy instruments and kits - market status and future development trends
Andwhere multiple or query ORM conditions in yii2
函数栈帧的创建与销毁
Variable declarations following if statements
random shuffle注意
The left value and the right finger explain better
How to implement append in tensor
Why choose a frame? What frame to choose
分布式事务
Three.js本地环境搭建
[principles of multithreading and high concurrency: 1_cpu multi-level cache model]
[Fuhan 6630 encodes and stores videos, and uses RTSP server and timestamp synchronization to realize VLC viewing videos]
I2C subsystem (IV): I2C debug
Wechat - developed by wechat official account Net core access
Check log4j problems using stain analysis
Concrete CMS vulnerability
Use cve-2021-43893 to delete files on the domain controller
Apple releases MacOS 11.6.4 update: mainly security fixes
[leectode 2022.2.15] lucky numbers in the matrix
Notifydatasetchanged not applicable to recyclerview - notifydatasetchanged not working on recyclerview