[1.0.0-alpha.3] TypeError: Cannot read property 'jquery' of null
See original GitHub issueI’m using MaterializeCSS + VueJS with Laravel Webpack.
Expected Behavior
Initializing the form when the component is loaded.
Current Behavior
[Vue warn]: Error in mounted hook: "TypeError: Cannot read property 'jquery' of null"
Steps to Reproduce (for bugs)
//...
data() {
return {
modalId: 'modal-order'
}
},
mounded() {
this.init();
},
methods: {
init() {
let elem = document.querySelector(`#${this.modalId}`);
this.instance = M.Modal.init(elem, {
onOpenStart: () => {
this.show();
},
onCloseEnd: () => {
this.resetForm();
}
});
}
}
Possible Solution
If you execute the code after jQuery is loaded, the error disappears:
//...
data() {
return {
modalId: 'modal-order'
}
},
mounded() {
this.init();
},
methods: {
init() {
$(document).ready(() => {
let elem = document.querySelector(`#${this.modalId}`);
this.instance = M.Modal.init(elem, {
onOpenStart: () => {
this.show();
},
onCloseEnd: () => {
this.resetForm();
}
});
});
}
}
Your Environment
- Version used: 1.0.0-alpha.3
- Browser Name and version: All latest browsers (Google Chrome, Mozilla Firefox, Microsoft Edge, Opera)
- Operating System and version (desktop or mobile): Windows 10 Pro desktop, Windows 7 desktop.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Uncaught TypeError: Cannot read property 'val' of null jquery
I'm trying to pass form values, check them and then return the response with jquery, everything gets passed correctly, the image gets ...
Read more >Uncaught TypeError: Cannot read property of null - iDiallo
This will result in Uncaught TypeError: Cannot read property 'value' of null . The reason will be that the element with id input...
Read more >cannot read properties of null (reading '0') react
Solution: The TypeError: Cannot read properties of null (reading 'data') occurs when your first render, your data with that id isn't mounted to...
Read more >Cannot read property 'data' of null
Hey, I have this problem, but can`t resolve. Some can help me? Website: https://escolabrasileirademedicina.com.br. Uncaught TypeError: Cannot ...
Read more >Uncaught TypeError: Cannot read property 'nTable' of null
Uncaught TypeError: Cannot read property 'nTable' of null ... dataTables.min.js:83) at Function.each (jquery-2.2.3.min.js:2) at ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Try using https://vuejs.org/v2/api/#ref instead of query selector in Vue
Hmm … I did not think about it, thanks 😃