Search code examples
javascriptvue.jswebpackapexcharts

Unable to add any module without WebPack


I'm using a basical Vue Routing

const routes = [
     { path: "/home", component: Home }
];
const router = new VueRouter({
  routes // short for `routes: routes`
});

const app = new Vue({
  router
}).$mount("#app");

Took from this green exemple : Can we make vue.js application without .vue extension component and webpack?

Everything is working flawless . I 'm not using webpack.

Now, I'm adding the APEXCHARTS library inside of index.html

<script src="https://cdn.jsdelivr.net/npm/apexcharts" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-apexcharts" type="module"></script>

This is one my component , using literals

const Home = {
  data: function() {
    return {
      options: {
        chart: {
          id: 'vuechart-example'
        },
        xaxis: {
          categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998]
        }
      },
      series: [{
        name: 'series-1',
        data: [30, 40, 45, 50, 49, 60, 70, 91]
      }]
    }
  },
  template:
    '<div><apexchart width="500" type="bar" :options="options" :series="series"></apexchart></div>'
};

and this is the error

[Vue warn]: Unknown custom element: <apexchart> - did you register the component correctly? For recursive components, make sure to provide the "name" option

My question is : how can I import this module, or any other module, without using WEBPACK, and using the vue 2 router ? I can't use 'IMPORT', it is not working, is there any way to mention the module name inside of the vue instantiation new Vue ?

Back in the days, ANGULARJS needed the modules names , but there, i dont know where to add the module name , I can not use the IMPORT syntax, please help.

Thank you

EDIT : I've done a FIDDLE : https://jsfiddle.net/nicolas1000/rke9xadq/


Solution

  • Try this:

    Where you need the <apexchart> tag, you can do the following:

    Vue.component('apexchart', VueApexCharts)