1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > Error in nextTick: “TypeError: Cannot read property ‘xxx‘ of undefined“

Error in nextTick: “TypeError: Cannot read property ‘xxx‘ of undefined“

时间:2022-05-16 11:31:04

相关推荐

Error in nextTick: “TypeError: Cannot read property ‘xxx‘ of undefined“

报这个错主要是因为子组件还没加载完成就对子组件进行赋值,推荐使用第一个

this.$nextTick( ()=> {//修改子组件的内容});//或setTimeout(() => {//修改子组件的内容}, 50);

父组件传值给子组件,子组件不能直接修改,会报错

//子组件修改父组件的值this.$emit('名字','值');//子组件调用父组件的方法this.$emit('方法', val)//或this.$parent.fatherMethod();//或<child :fatherMethod="fatherMethod"></child>props: {fatherMethod: {type: Function,default: null}},//父组件修改子组件的值<tag ref="xxx" @b='b'></tag>this.$refs.xxx.a = 1//父组件调用子组件的方法this.$refs.xxx.b()

watch中设置参数说明:有变化才能被监听

deep:是否深度监听

immediate:是否在页面初始化时就启用,true:是

//监听files变化watch: {files: {handler (newValue, oldValue) {console.log(newValue)this.fileList = newValue},deep: true // 默认值是 false,代表是否深度监听}}

//监听对象的变化data() {return {files: {name: 'demo'} }},watch: {files: {handler(newValue, oldValue) {console.log(newValue)},deep: true}}

//监听对象的具体属性data() {return {files: {name: 'demo'} }},computed: {filesName() {return this.files.name}},watch: {filesName(newValue, oldValue) {console.log(newValue)}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。