Hi there
I am attempting to follow the Charting and You: A Graph Vue Component video. I can get my chart displaying no problem using just javascript and html. However when I try to put Vue into the mix I am just getting a blank screen.
Here is my view code:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div class="container">
<graph></graph>
</div>
<script src="/js/graphs.js"></script>
</body>
</html>
And my webpack.mix.js
const { mix } = require('laravel-mix');
mix.js('resources/assets/js/app.js', 'public/js')
.js('resources/assets/js/graphs.js', 'public/js')
.less('resources/assets/less/app.less', 'public/css');
My resources/assets/js/graphs.js:
import Vue from 'vue';
import Graph from './components/Graph'
new Vue({
el: '.container',
components: {
Graph
}
});
And finally my ./components/Graph.js
import Chart from 'chart.js';
export default {
template: '<canvas width="600" height="400" id="myChart"></canvas>',
ready() {
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [
{
label: "2015",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [65, 59, 80, 81, 56, 55, 40]
}
]
};
var context = document.getElementById('myChart').getContext('2d');
var myLineChart = new Chart(context, {
type: 'line',
data: data,
options: {
title: {
display: true,
text: 'Test Chart'
}
}
});
}
}
When I run npm run dev everything compiles nicely. And I am receiving no errors in my dev tools Console. Under my vue-devtools screen I can see < Root > then < Graph > == $vm0, when I select < Graph > I then see: This instance has no reactive state.
Package.json
{
"private": true,
"scripts": {
"dev": "node ./node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "node ./node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"hot": "node ./node_modules/cross-env/bin/cross-env.js NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"production": "node ./node_modules/cross-env/bin/cross-env.js NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.15.3",
"bootstrap-sass": "^3.3.7",
"jquery": "^3.1.1",
"laravel-mix": "^0.7.2",
"lodash": "^4.17.4",
"vue": "^2.1.10"
},
"dependencies": {
"chart.js": "^2.5.0",
"vue": "^2.2.1",
"vue-template-compiler": "^2.2.1"
}
}
Any suggestions on what I may have missed would be most appreciated!
Thanks
Luke