现在input v-model 绑定的是vuex中的mapstate 所有的data数据都是存在了sate里面 ,现在需要通过prop进行验证。 如果使用普通的方法进行验证就会报错。找不到我prop里的属性。一直为空的。
// from 部分
<el-form ref="form" :model="form" label-width="80px" >
<el-form-item label="姓名" >
<el-input v-model="form.information.name"></el-input>
</el-form-item>
//计算属性部分 v- model 是 通过解构 mapState 中的form 来的
computed: {
...mapGetters(["getUserLshInfo"]),
...mapState([
"form",
"defaultData",
"addresSheng",
"shengValue",
"addressShi",
"shiValue",
"addressXian",
"xianValue",
"addressXiang",
"xiangValue",
"addressCun",
"cunValue",
]),
},
//数据为vuex中state里面的
form: {
information:{
name:''
}
}
参考:
<template>
<el-dialog
:title="!dataForm.areaId ? '新增' : '修改'"
:close-on-click-modal="false"
:visible.sync="visible"
width="50%"
>
<el-form ref="dataForm" :model="dataForm" :rules="dataRule" label-width="100px" style="width:95%;" @keyup.enter.native="dataFormSubmit()">
<el-row>
<el-col :span="24">
<el-form-item label="考区名称" prop="areaName">
<el-input v-model="dataForm.areaName" placeholder="请输入考区名称" />
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="排序" prop="seq">
<el-input v-model="dataForm.seq" placeholder="请输入排序" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button type="danger" @click="visible = false">取 消</el-button>
<el-button type="primary" @click="dataFormSubmit()">确 定</el-button>
</span>
</el-dialog>
</template>
<script>
import { getInfo, add, edit } from '@/api/sys/area'
export default {
data() {
return {
visible: false,
dataForm: {
areaId: '',
areaName: '',
seq: '1'
},
dataRule: {
areaName: [
{ required: true, message: '考区名称不能为空', trigger: 'blur' }
],
seq: [
{ required: true, message: '排序不能为空', trigger: 'blur' }
]
}
}
},
methods: {
init(id) {
this.dataForm.areaId = id
this.visible = true
this.resetForm('dataForm')
this.dataForm.seq = 1
if (this.dataForm.areaId) {
getInfo(id).then(res => {
if (res && res.code === 200) {
this.dataForm.areaId = res.data.areaId
this.dataForm.areaName = res.data.areaName
this.dataForm.seq = res.data.seq
}
})
}
},
// 表单提交
dataFormSubmit() {
this.$refs['dataForm'].validate((valid) => {
if (valid) {
const param = {
'areaId': this.dataForm.areaId,
'areaName': this.dataForm.areaName,
'seq': this.dataForm.seq
}
if (!this.dataForm.areaId) {
add(param).then(res => {
this.returnResponse(res)
})
} else {
edit(param).then(res => {
this.returnResponse(res)
})
}
}
})
}
}
}
</script>