P
P
panikev2019-09-03 12:08:39
Vue.js
panikev, 2019-09-03 12:08:39

How to fix a bug in a Vue project?

Hello! Below is a piece of code

<template>
<div class="col-sm">
        План составляет: {{tasks[0].title}}
      <div id="chart">
    </div>
     </div>
</template>
<script>
  export default {
        data() {
       return {
         tasks: [],
    },
 mounted(){
var chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();
</script>

Please tell me why when adding {{tasks[0].title}}, when starting the project, the error "TypeError: Cannot read property 'querySelectorAll' of undefined" is displayed in the console. If I remove this reference to the element, then the project is launched.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexey, 2019-09-03
@AleksRap

You have mounted hook, data object and export default are not closed

K
Konstantin Kitmanov, 2019-09-03
@k12th

If you are using querySelector in vue, you are most likely doing something wrong. In 99.9% of cases, you should use ref :

<template>
  <div class="col-sm">
    План составляет: {{tasks[0].title}}
    <div ref="chart"></div>
  </div>
</template>

<script>
export default {
    data() {
        return {
            tasks: [],
        };
    },
    mounted() {
        var chart = new ApexCharts(this.$refs.chart, options);
        chart.render();
    },
};
</script>

A
Alexander, 2019-09-03
@UPSA

Just learning ... but I have my suspicions)))
1. https://ru.vuejs.org/v2/api/#mounted
2. tasks: [{title: 'Default',}], Can write something to the array?
3. Code truncated ... syntax. Maybe you stuck mounted() in the wrong place.

G
grinat, 2019-09-03
@grinat

To be honest, these are pretty shitty charts. You can see the implementation here: https://github.com/apexcharts/vue-apexcharts/blob/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question