Tips for bringing in and taking out data in Vue

I have a set of files called total.vue and completeness.vue. I aim to display the chart from total.vue within completeness.vue, which is my designated admin dashboard where I plan to feature 2 or 3 additional charts.

For this task, I will be exporting content from total.vue


<script>

    import Chart from 'chart.js';
    import JQuery from 'jquery'
    let $ = JQuery
    export default {
        name: 'total_chart',
        mounted() {
            var chart_total = this.$refs.chart_total;
            const ctx = chart_total.getContext("2d");
            const myChart = new Chart(ctx, {
                type: 'bar',
    ...
    ...
    ...
</script>

Within completeness.vue, I will then proceed to import as follows:

<template>
    <div id="total_chart">
        <div id="content">
            <canvas ref="chart_total"></canvas>
        </div>
    </div>
</template>

<script>

import  chart_total  from '@/components/total'

export default {
  components: {
    chart_total
  } 

</script>

Despite my efforts, I am not getting any output when accessing the route originally assigned to completeness.vue.

Any suggestions on how to troubleshoot this issue would be greatly appreciated.

Thank you for your assistance.

Answer №1

It appears that your code is not correctly rendering the component. Here is how you should modify it:

<template>
    <custom-chart>
    </custom-chart>
</template>

<script>

import CustomChart from '@/components/custom'

export default {
  components: {
    CustomChart
  }
} 

</script>

Ensure that your custom-chart component looks like this:

<template>
        <div id="content">
            <canvas ref="chart_custom"&emdash;></canvas>
        </div>
</template>

<script>

    import Chart from 'chart.js';
    import JQuery from 'jquery'
    let $ = JQuery
    export default {
        name: 'custom-chart',
        mounted() {
            var chart_custom = this.$refs.chart_custom;
            const ctx = chart_custom.getContext("2d");
            const myChart = new Chart(ctx, {
                type: 'line',
    ...
    ...
    ...
</script>

Additionally, consider familiarizing yourself with proper component naming conventions: https://v2.vuejs.org/v2/guide/components-registration.html

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Any tips on how to retrieve the data from an AJAX request using vanilla JavaScript?

After successfully implementing my first AJAX call last week, I am now faced with a new challenge. This time, I need to not only change something onSuccess but also access the returned data. <script type="text/javascript"> function showMessage(j ...

I am encountering difficulties displaying the image and CSS files from another folder in my HTML with Node.js

I am facing difficulty in establishing a connection between my front-end and back-end using node.js. As a result, the website only displays the HTML code without linking to the CSS or image files. Here is the folder structure: root -src •pi ...

Angular.js controller unable to receive object array from $http.get in factory

I am fairly new to Angular development and I've hit a roadblock that's been holding me back for a while. My factory is successfully creating an array filled with objects, specifically RSS feed data, and I can see it loading in the console. Howev ...

ReactJS - Element not specified

I'm experiencing a specific issue with the component below related to the changeColor() function, which is triggering an error message: TypeError: Cannot set property 'color' of undefined This error seems to be isolated within this compo ...

How about inputting some text into a field?

Below is the code snippet for your reference: <div class="col-xs-12 col-sm-9"> <input id="Shipping_FirstName" name="firstname" ng-model="userOrder.Shipping.FirstName" type="text" class="form-control nsg-form--input ng-pristine ng-untouc ...

Basic jQuery template design

Currently, I am developing a user interface that allows users to add or delete items with a similar layout. The process starts with one item and by clicking 'add', more items can be added. These items come in several different types. My current ...

``There seems to be an issue with implementing the SlideDown feature in JavaScript

I am having an issue with a code where the expected behavior is to slide down a div when a person hovers over text, but it's not working. Can someone please review and identify the cause of this problem? <script type="text/javascript" src="/js/jqu ...

Error message: The specified file or directory does not exist and cannot be unlinked

fs.unlink('backup/' + 'test') An issue arises when attempting to delete a folder: { [Error: ENOENT: no such file or directory, unlink 'backup/test'] errno: -2, code: 'ENOENT', syscall: 'unlink', p ...

The Error message "Property 'data' is not present in Type <void> | AxiosHttpResponse<any>" is indicating that the data property is missing on

When I fetch data for a specific user, I have a promise that I use to setState. Below is the implementation: getUserUsername = (): string => { const { match } = this.props; return match.params.username; }; onFetchUser = () => getUse ...

Having trouble with AJAX within AJAX not functioning properly?

Similar to the Facebook commenting system, I am aiming for comments to be appended to previous ones and displayed all at once. However, currently the comments only show up after the page is reloaded. Please Note: Each post initially loads with just two co ...

VuePress - markdown document imbued with unique symbols

As I was attempting to follow the get-started tutorial for VuePress, I encountered an unexpected result when running the application for the first time: # Hello VuePress I thought it might be a PowerShell issue, so I modified the text. However, the outpu ...

I'm just getting started: an image carousel featuring a unique twist with random quote overlays, but there's a catch - it only activates on the very first image... what comes next?

After successfully displaying the generator over the first image, I encounter a problem with the second and third images where it seems to disappear. However, upon cycling back to the first slide, the generator reappears with a different quote. I've a ...

Adjust the height to match the shortest sibling child div height

In my layout, I have multiple rows with each row containing multiple columns. Within each column, there is a div and a paragraph - the div contains an image. My goal is to set the div with the class cover-bg to the lowest height of cover-bg in the same row ...

Tips for securely duplicating an item from the state to prevent the view from altering the store directly

On my profile page, I wanted to allow users to update their information. Initially, I fetched the data from the store using: this.$store.state.auth.user However, when I tried binding this data to input controls using v-model, the <input> element wo ...

Leveraging the power of the underscore library within the WordPress

I'm currently utilizing the underscore library for handling arrays. I have included the library using the code snippet below in my functions.php file add_action( 'wp_enqueue_scripts', 'jt_enqueue_scripts' ); function jt_e ...

Having issues with passing POST data during file handling operations

I am attempting to utilize Ajax POST on my WordPress website to check if checkboxes are selected and update their values in the database upon clicking a button. Although using the standard PHP form submission is the simplest method, the fields that I need ...

Transforming a simple MySQL query into a structured nested JSON format

Is there a way to easily reorganize data without using complex for loops (perhaps with Underscore.js or refining the MySQL query)? I have data formatted like this: [ { "J_NUM": "BOAK-1212", "X_DUE_DATE": "2012-06-20T00:00:00.000Z", "X_LEAD_T ...

Discovering the final pattern using regular expressions

var inputString = 'a.b.c.d.e.f'; var pattern = inputString.match(/([^\.]+)\.[^\.]+$/)[1]; console.log(pattern); I have successfully implemented the code using regular expressions, but I am open to exploring more efficient solution ...

Exporting a module with Node.js is a crucial aspect of building

Within my custom module, I have successfully set up an export function. module.exports = function(callback) { var request = require("request") var url = "http://sheetsu.com/apis/94dc0db4" request({ url: url, json: true }, ...

The function createVNode does not exist in the context of Vue integrated with Laravel

I've been attempting to replicate a component rendering based on an online example. While it works smoothly in a sample project, it crashes when applied to the official codebase. Here is the content of the blade file being rendered: <html lang=&q ...