Error in mounted hook: "TypeError: Cannot set property 'bottom' of undefined"

tags: Error in mounted hook: "TypeEr

The template in the parent component music-list.vue calls the child component scroll

<scroll ref="list" @scroll="scroll" :data="songs" :probeType="probeType" :listenScroll="listenScroll" class="list">

Set the bottom value of the root element of the child component in a method in the methods of the parent component music-list.vue

this.$refs.list.style.bottom = bottom
Then the following error is reported in the browser: roughly means that the attribute bottom cannot be set because it is not defined; the error is the error in line 79 in the method handlePlaylist() in the music-list.vue file, which is this.$refs.list.style.bottom = bottom is wrong

   
 vue.esm.js?efeb:1741 TypeError: Cannot set property 'bottom' of undefined    at VueComponent.handlePlaylist (music-list.vue?f694:79)    at VueComponent.activated (mixin.js?98c1:18)    at callHook (vue.esm.js?efeb:2921)    at activateChildComponent (vue.esm.js?efeb:2894)    at activateChildComponent (vue.esm.js?efeb:2892)    at activateChildComponent (vue.esm.js?efeb:2892)    at Object.insert (vue.esm.js?efeb:4169)    at invokeInsertHook (vue.esm.js?efeb:5960)    at Vue.patch [as __patch__] (vue.esm.js?efeb:6179)    at Vue._update (vue.esm.js?efeb:2660)logError @ vue.esm.js?efeb:1741globalHandleError @ vue.esm.js?efeb:1732handleError @ vue.esm.js?efeb:1721callHook @ vue.esm.js?efeb:2923activateChildComponent @ vue.esm.js?efeb:2894activateChildComponent @ vue.esm.js?efeb:2892activateChildComponent @ vue.esm.js?efeb:2892insert @ vue.esm.js?efeb:4169invokeInsertHook @ vue.esm.js?efeb:5960patch @ vue.esm.js?efeb:6179Vue._update @ vue.esm.js?efeb:2660updateComponent @ vue.esm.js?efeb:2788get @ vue.esm.js?efeb:3142Watcher @ vue.esm.js?efeb:3131mountComponent @ vue.esm.js?efeb:2795Vue.$mount @ vue.esm.js?efeb:8540Vue.$mount @ vue.esm.js?efeb:10939Vue._init @ vue.esm.js?efeb:4640Vue @ vue.esm.js?efeb:4729(anonymous) @ main.js?1c90:25.c/main.js @ app.js:2923__webpack_require__ @ app.js:679fn @ app.js:890 @ app.js:2988__webpack_require__ @ app.js:679(anonymous) @ app.js:725(anonymous) @ app.js:728 


analysis: According to this.$refs.list.style.bottom = bottom, we can know that the intention is to get the DOM root element of the child component, and then set a value to the css attribute bottom of this element, but because this.$refs.list is only obtained The component, and cannot get the DOM inside the sub-component, this is the reason for the error

Solution: Get the DOM of the child component through the $el option, which is rewritten as: this.$refs.list.$el.style.bottom = bottom, that is, this.$refs.list.$el can get the DOM of the child component


Intelligent Recommendation

Vue echarts initialization example "Error in mounted hook: "TypeError: Cannot read property ‘init’ of undefined""

Vue echarts initialization example "Error in mounted hook: "TypeError: Cannot read property ‘init’ of undefined"" You can see that there is no problem with downloading ...

[Vue warn]: Error in mounted hook: “TypeError: Cannot read property ‘coordinateSystem‘ of undefined“

background: When using the ECharts chart component in a Vue project, this error message appeared and the chart could not be displayed normally...

UNI-APP_uni-app reports Error in mounted hook: “TypeError: Cannot read property ‘length’ of undefined when running on h5

uni-app runs on the h5 end and reports Error in mounted hook: "TypeError: Cannot read property ‘length’ of undefined Can run normally but report an error At first, I couldn't find the...

[Vue warn]: Error in mounted hook: “TypeError: Cannot read property ‘init‘ of undefined“

The following problem occurs is to report the following error when using official examples in mounted (): Error in mounted hook: “TypeError: Cannot read property ‘init’ of undefined&...

[Vue warn]: Error in mounted hook: “TypeError: Cannot read property ‘init’ of undefined”

In the first two days, I encountered the following error when using the Echarts chart: Reason for error: Echarts' introduction method error Correct Echarts introduction method: This is solved in this ...

More Recommendation

[Vue warn]: Error in mounted hook: “TypeError: Cannot read property ‘init’ of undefined“

[Vue warn]: Error in mounted hook: "TypeError: Cannot read property ‘init’ of undefined" TypeError: Cannot read property ‘init’ of undefined Solution: Change import e...

Exception in thread &amp;amp;quot;main&amp;amp;quot; error when deploying web project

The main reason: the JDK version used by the container does not match For example, tomcat7 does not support JDK5, which is a fundamental problem. Solution: Use the matching JDK according to the corres...

Input.GetAxis(&amp;quot;&amp;quot;) Input.GetAxisRaw(&amp;quot;&amp;quot;)

Input.GetAxis Get axis static function GetAxis (axisName : string) : float Descriptiondescription Returns the value of the virtual axis identified by axisName. Returns the value in the ...

The content of element type &amp;quot;select&amp;quot; must match &amp;quot;(include|trim|where|set|foreach|choo

Today encounter a strange question, I write a sql statement directly in the mysql database visualization tool sqlyog, paste directly into the project xml file directly suggestive of error, at first I ...

Error in mounted hook: “TypeError: Cannot read properties of undefined (reading ‘init‘)“

The front -end Vue project uses an ECharts error solution, which is valid for pro -testing. (1) Originally introduced echarts as follows: the following code: (2) The writing of ECharts was introduced ...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top