No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Trigger/call function when component is rendered?

    Help
    2
    4
    804
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      dirkhd last edited by

      Is there a way to once call a function when as soon as a component is rendered - so to say a kind of @click but in the sense of @loaded?

      I use Apexcharts and fetch data via Axios. I call the function to get the data inside mounted() and also use $nextTick.

      mounted() {
          this.$nextTick(function() {
              this.getProjectAnalysis();  // this calls function with Axios getting the data
       });
      

      But from time to time the Apex component seems not ready cause updating the data with updateOptions() runs into an error. Console says “Cannot read property ‘updateOptions’ of undefined”.

      Maybe someone has an idea for a workaround?

      beets 1 Reply Last reply Reply Quote 0
      • beets
        beets @dirkhd last edited by

        @dirkhd Apexcharts seems to have its own mounted event: https://apexcharts.com/docs/options/chart/events/

        Some more information on how you integrate Apex, but assuming you’re using the vue component, something like this maybe?

        <template>
        <div>
          <apexchart width="500" type="bar" :options="options" :series="series"></apexchart>
        </div>
        </template>
        <script>
        export default {
          data() {
            return {
              options: {
                chart: {
                  events: {
                    mounted: (chartContext, config) => {
                      this.getProjectAnalysis()
                    }
                  }
                }
              }
            }
          }
        }
        </script>
        

        Completely untested, just what I would try from looking at the docs

        1 Reply Last reply Reply Quote 1
        • D
          dirkhd last edited by

          @beets You are awesome 🙂

          It works and in addition this also solved my second problem. Because when you use Apex inside tabs then the chart disappears (at least the part with the data, not the legend) in case you switch between the tabs. But no the chart is “refilled” with the data because the function is called again.

          beets 1 Reply Last reply Reply Quote 0
          • beets
            beets @dirkhd last edited by

            @dirkhd Great, glad I could help. It wasn’t entirely obvious from the docs alone, I also took a look at the vue component source code here: https://github.com/apexcharts/vue-apexcharts/blob/master/src/ApexCharts.component.js

            So just as a reference, you can add anything from the options API here: https://apexcharts.com/docs/options/annotations/ (I just linked to annotations page, but any other would work.

            1 Reply Last reply Reply Quote 1
            • First post
              Last post