props里的值是只读的,不能直接修改props的值,准备修改的时候要把它里面的值转存到data(){return{}}中
假如在组件中,操作不到父组件通过自定义属性传来的值得时候,这时,我们可以利用$nextTick()这个回调函数,等DOM全都更新完再操作
子组件中
props: {
// 父级的部门的id
id: {
type: String,
required: true
}
}
methods:{
async getDataFn() {
const res = await editDepatrmentAPI(this.id)
console.log('hhhh', res)
this.form = res.data
}
}
在父组件中
<add-edit
:id="curId"
ref="editDialog"
></add-edit>
import AddEdit from './AddEdit.vue'
components: { AddEdit },
editDepartmentFn(id) {
this.curId = id
this.$nextTick(() => {
this.$refs.editDialog.getDataFn()
})
},