具体实现
子组件定义
<template>
<div class="container">
<LabelName />
<div class="input_sty">
<input :value="row.address" @input="input"></input>
<div v-if="isShowMsg">地址不可为空 </div>
</div>
</div>
</template>
<script>
import LabelName from './labelName.vue'
export default {
components: {
LabelName
},
props:{
row:Object
},
mounted(){
this.isShowMsg = this.$attrs.reg.test(this.row.address)
},
data() {
return {
isShowMsg:false
}
},
methods: {
input(event){
this.row.address = event.target?.value
this.isShowMsg = this.$attrs.reg.test(this.row.address)
console.log( this.isShowMsg);
this.$emit('changeRow',this.row)
}
},
watch:{
'row.address'(value){
}
}
}
</script>
<style scoped>
.img {
width: 20px;
height: 20px;
}
.container {
display: flex;
width: 40%;
.input_sty{
display: flex;
flex-direction: column;
}
}
span {
margin-left: 5px;
margin-top: 4px;
}
input{
border: 1px solid navy;
height: 30px;
}
</style>
父组件传参
<template #default="{ row }">
<InfoSource
@changeRow="changeRow"
:row="row"
:reg="reg"
/>
</template>
效果展示

