当前位置:网站首页>后管中编辑与预览获取表单的值写法
后管中编辑与预览获取表单的值写法
2022-07-03 02:53:00 【疤痕体】
Vue中将data中的某一个对象里面的值或者属性置空
在项目中我们会遇到初始化数据的问题,可以 this.xxx = ‘’,这种方式是常用的,但是如果是data里面的数据,这种方式就会使代码看起来有些冗余。
那么,我们可以使用this.assign()方法或是Json
//这个笨方法 但是如果要多个按钮同时需要清空需要一个个来写
data(){
return{
ismenu: {
name: "",
sex: '',
age: '',
birth: "",
address: "",
},
}
}
//清空ismenu的数据值
PS后管时预览与编辑添加共用一个弹出层 预览添加完后
添加编辑数据也会自动添加,这个时候我们需要在添加编辑按钮点击时进行情况数据
一般笨方法是这种 但是太冗余 大可不必
this.ismenu.name = "";
this.ismenu.sex = "";
this.ismen.age= "";
this.ismenu. birth= "";
this.ismenu.address = "";
this.assign()方法
// 初始化所有data数据
Object.assign(this.$data, this.$options.data())
// 初始化data数据中的某一个数据
Object.assign(this.$data.xxx, this.$options.data().xxx)
PS 你要单独清空ismen对象的值需要
Object.assign(this.$data.ismen, this.$options.data().ismen)
Json
Json 先在data中定义 xxx:[{
a:1}],在methods中的方法中 清空数据(初始化)
this.xxx = JSON.parse(JSON.stringify(this.xxx))
获取表单的值
一般来说编辑当中会得到值把值赋值过去
//slot-scope="scope" 这个是elem框架给出的方法
// scope.$index获取索引值 , scope.row获取对应的值
<template slot-scope="scope">
<el-button
size="mini"
style="margin: 0"
@click.stop="btnedit(scope.$index, scope.row)">编辑</el-button>
</template>
// 这个就是获取到对应的值了
//然后通过点击打印就可以看到里面的方法了
btnedit(index,scope){
console.log(index,scope)//打印得到获取的值
}
还有就是你在编辑的同时,你要拿到表单里面对应的值啊比如这种
<el-form :model="ismenu" ref="ismenu" :rules="editFormRules">
<!-- 姓名 性别 年龄 生日 地址 -->
<el-form-item label="姓名" prop="name">
<el-input
style="width: 60%"
v-model="ismenu.name"
autocomplete="off"
:disabled="titleResult[dialogStatus] == '预览'"
></el-input>
</el-form-item>
<el-form-item label="性别" prop="sex">
<el-radio-group
v-model="ismenu.sex"
:disabled="titleResult[dialogStatus] == '预览'"
>
<el-radio :label="1">男</el-radio>
<el-radio :label="0">女</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="年龄" prop="age">
<el-input-number
v-model="ismenu.age"
:min="0"
:max="200"
:disabled="titleResult[dialogStatus] == '预览'"
></el-input-number>
</el-form-item>
<el-form-item label="生日" prop="birth">
<el-date-picker
v-model="ismenu.birth"
type="date"
:disabled="titleResult[dialogStatus] == '预览'"
placeholder="选择日期"
>
</el-date-picker>
</el-form-item>
<el-form-item label="地址" prop="addr">
<el-input
type="textarea"
style="width: 60%"
v-model="ismenu.addr"
show-word-limit
placeholder="请输入地址"
:disabled="titleResult[dialogStatus] == '预览'"
:maxlength="1024"
></el-input>
</el-form-item>
</el-form>
//然后呢 你要在data里面定义你的值
ismenu: {
//表单的要与后端要求的入参保持一致
name: "",
sex: -1,
age: 0,
birth: "",
addr: "",
},
最重要的来咯
当你在这边改变或者添加数据时
你肯定要拿到model的值吧
//拿编辑举列
btnedit(index,scope){
this.$nextTick(() => {
// 一般赋值是这样写 但是这个是笨方法
// (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);
// 可以这样来赋值使用枚举的方法直接全部拿到
this.ismenu=Object.assign({
}, scope)
}));
}
//然后你这样后有添加 添加就会自动赋值这个时候你需要
还原就是初始化 ismenu表单的值
一般我们会这样写
// (this.ismenu.name = ''),
// (this.ismenu.sex =''),
// (this.ismenu.age =''),
// (this.ismenu.birth = ''),
// (this.ismenu.addr = '');
直接这样
Object.assign(this.$data.ismenu, this.$options.data().ismenu);
这个方法
// 初始化所有data数据
Object.assign(this.$data, this.$options.data())
// 初始化data数据中的某一个数据
Object.assign(this.$data.xxx, this.$options.data().xxx)
这个是在添加的时候添加成功加上 防止下回点击添加 上次添加内容还在
this.$refs["ismenu"].resetFields();// 清空表单内容 以防下回点击原数据还在
边栏推荐
- [shutter] bottom navigation bar page frame (bottomnavigationbar bottom navigation bar | pageview sliding page | bottom navigation and sliding page associated operation)
- SqlServer行转列PIVOT
- [C语言]给账号密码进行MD5加密
- Random shuffle note
- Segmentation fault occurs during VFORK execution
- Source code analysis | layout file loading process
- Use optimization | points that can be optimized in recyclerview
- 当lambda没有输入时,是何含义?
- Didi programmers are despised by relatives: an annual salary of 800000 is not as good as two teachers
- I2C 子系统(一):I2C spec
猜你喜欢

Baidu map - surrounding search

Check log4j problems using stain analysis

用docker 连接mysql的过程
![[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]

SQL statement

Today, it's time to copy the bottom!
![[shutter] bottom navigation bar page frame (bottomnavigationbar bottom navigation bar | pageview sliding page | bottom navigation and sliding page associated operation)](/img/6e/67bc187a89fb9125856c78c89f7bfb.gif)
[shutter] bottom navigation bar page frame (bottomnavigationbar bottom navigation bar | pageview sliding page | bottom navigation and sliding page associated operation)

函数栈帧的创建与销毁

Kubernetes family container housekeeper pod online Q & A?

Three. JS local environment setup
随机推荐
一文带你了解 ZigBee
[shutter] banner carousel component (shutter_wiper plug-in | swiper component)
I2C 子系統(四):I2C debug
Kubernetes family container housekeeper pod online Q & A?
Introduction to cron expression
[C language] MD5 encryption for account password
左值右指解释的比较好的
【翻译】具有集中控制平面的现代应用负载平衡
where 1=1 是什么意思
[translation] flux is safe. Gain more confidence through fuzzy processing
2022-2028 global splicing display industry research and trend analysis report
Check log4j problems using stain analysis
leetcode540
Kubernetes cluster log and efk architecture log scheme
Add automatic model generation function to hade
迅雷chrome扩展插件造成服务器返回的数据js解析页面数据异常
左连接,内连接
How to change the panet layer in yolov5 to bifpn
The Linux server needs to install the agent software EPS (agent) database
Error when installing MySQL in Linux: starting mysql The server quit without updating PID file ([FAILED]al/mysql/data/l.pid