[Vuejs]-Error : Cannot read property 'querySelectorAll' of null

3đź‘Ť

âś…

Instead of created() {} to init your Chartist, you must use the mounted() {} method to init your chart only on client side.

mounted() {
  this.creatChart();
},

The “created” hook will be run twice once on server-side, then once on client-side. The “mounted” will be run only once on client-side.

Chartist is only available on client-side (browser), due to the usage of document.querySelectorAll.

But on server-side (Node.js), document does not exist… which explains your error of Cannot read property 'querySelectorAll' of null.

Leave a comment