form表单的学习
<el-date-picker
v-model="ruleForm.birth"
type="date"
placeholder="选择生日"
format="yyyy 年 MM 月 dd 日"
value-format="yyyy-MM-dd">
</el-date-picker>
<el-upload
class="avatar-uploader"
:action="uploadAction"
:on-success="handleAvatarSuccess"
:before-upload="beforeAvatarUpload"
>
<img v-if="imageUrl" :src="imageUrl" class="avatar" />
<i v-else class="el-icon-plus avatar-uploader-icon" style="border: 1px dashed #d9d9d9"> </i>
</el-upload>
uploadAction: `${process.env.VUE_APP_DEVELOPMENT_SERVER_URL}/upload/uploadPicture`,
handleAvatarSuccess(res) {
this.imageUrl = `${process.env.VUE_APP_DEVELOPMENT_SERVER_URL}/public${res.data.url}`
},
beforeAvatarUpload(file) {
const isType =
file.type === 'image/jpeg' ||
file.type === 'image/jpg' ||
file.type === 'image/png' ||
file.type === 'image/bmp'
const isLt2M = file.size / 1024 / 1024 < 2.5
if (!isLt2M) {
this.$message.error('上传头像图片大小不能超过 2.5MB!')
}
if (!isType) {
this.$message.error('上传图片格式错误!')
}
if (file.name.length >= 100) {
this.$message.error('图片名字超长,请换一张图片!')
}
return isType && isLt2M
},
<el-form-item label="性别" prop="sex">
<el-select v-model="ruleForm.sex" placeholder="请选择性别">
<el-option
:value="item.dictValue"
:label="item.dictLabel"
v-for="(item, index) in sexList"
:key="index">
</el-option>
</el-select>
</el-form-item>
<el-form-item size="small" label="所属地区:" class="area" prop="province" placeholder="请选择城市">
<el-select placeholder="省份" v-model="form.province">
<el-option v-for="(item, index) in provinceList" :key="index" :label="item.name" :value="item.id">
{{item.name}}
</el-option>
</el-select>
<el-select placeholder="市区" v-model="form.city">
<el-option v-for="(item, index) in cityList" :key="index" :label="item.name" :value="item.id">
{{item.name}}
</el-option>
</el-select>
<el-select placeholder="街道" v-model="form.county">
<el-option v-for="(item, index) in countyList" :key="index" :label="item.name" :value="item.id">
{{item.name}}
</el-option>
</el-select>
</el-form-item>
data(){
return{
provinceList: [],
cityList: [],
countyList: [],
form:{
province:"",
city:'',
county:''
}
}
}
created() {
findProvinceApi().then((res) => {
this.provinceList = res.data
})
},
watch: {
'form.province': function () {
this.form.city = ''
this.countyList = []
findCityApi({ id: this.form.province }).then((res) => {
this.cityList = res.data
})
},
'form.city': function () {
this.form.county = ''
findCityApi({ id: this.form.city }).then((res) => {
this.countyList = res.data
})
},
deep: true,
},