简体   繁体   中英

Import js file from node_modules in vue-cli app

I've installed this with npm : https://github.com/hchstera/vue-charts

Doing npm install hchs-vue-charts

Which is a package to make charts in my views.

这是我的项目,我想在Dashboard.vue组件上使用ChartJS

I just want to know how to import this lib from node_modules in a single component in Vuejs with the Vue-cli app ( https://github.com/vuejs/vue-cli ) because in their examples they do it with an instance of Vue.

Thank you

In main.js import vue-charts and init the plugin like this:

import VueCharts from 'hchs-vue-charts'

Vue.use(VueCharts)

you must install module in main.js

import Vue from 'vue'
import VueCharts from 'hchs-vue-charts'

Vue.use(VueCharts)

then use component everywhere in you app, like this:

<template>
  <div id="app">
    <chartjs-line></chartjs-line>
  </div>
</template>

other components in lib:

<chartjs-bar/>
<chartjs-horizontal-bar/>
<chartjs-radar/>
<chartjs-polar-area/>
<chartjs-pie/>
<chartjs-doughnut/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM