How to import Chart.js with Webpack

自作多情 提交于 2020-02-27 04:27:27

问题


I have a Vue JS project using Webpack and need to import Chart.js. I have tried

// import Chart from 'chart.js/Chart.min.js'

This gives js errors when trying to use the library.


回答1:


After you do npm install chart.js,

You can simply use

import Chart from 'chart.js'

to import chart.js Hope it helps.




回答2:


As seen on this issue, if you use Angular CLI you only need to add this to the scripts array in angular-cli.json:

"../node_modules/chart.js/dist/Chart.bundle.min.js"

Restart your application, live reload won't do the trick.



来源:https://stackoverflow.com/questions/36024087/how-to-import-chart-js-with-webpack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!