0

I am doing report through chartjs.

In User.vue

beforeCreate() {
    axios
      .get("/pct-at/api/users")
      .then((res) => {
        console.log(res.data);
      })
      .catch((error) => {
      });
  },
  data() {
    return {
      startDate: "",
    };
  },

Result res.data :

{"datasets":[{"label":"User active","data":[2,0,0,0,0,0,0,0],"fill":false,"borderColor":"#9ec6cb"}}

In userChart.js

export default {
    lineChart: {
        options: {
            responsive: true,
            maintainAspectRatio: false,
            backgroundColor: false,
            hover: {
                mode: 'label',
            },
        },
        data: data // I want to get data from User.vue here : data
    },
}

Now I want in user.js to receive data in res.data from User.vue, how should I do that? Thanks

3
  • Why do you need this data in .js file? Please clarify your requirements and also add your full code Commented Sep 15, 2021 at 2:32
  • @mayank1513 On my question I also specified that I need to pass API data from .vue to .js in order for me to display chartjs? What more information do you need to help me? Commented Sep 15, 2021 at 3:47
  • 1
    I have added link to vue-chart-js official guide in my answer. Please follow that. Commented Sep 15, 2021 at 3:53

1 Answer 1

1

The best way to do this is to fetch data via axios call in userChart.js itself.

If you want to communicate between components, you can use custom events and props, event bus or mitt.

Specifically for chart.js, please follow the official guide here.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.