Home > Web Front-end > JS Tutorial > body text

How to use echarts in Vue.JS

php中世界最好的语言
Release: 2018-03-23 14:53:07
Original
2272 people have browsed it

This time I will show you how to use echarts in Vue.JS. What are the precautions for using echarts in Vue.JS? The following is a practical case, let's take a look.

The previous article introduced you to a detailed example of using ECharts in webpack. You can click to view it.

1. Use NPM to install (global import)

Execute the following command:

npm install echarts--save
Copy after login
Introduce echarts module

Introduce the echarts module into the main.js of the Vue project, that is, write the following code:

import echarts from 'echarts'
Vue.prototype.$echarts = echarts;
Copy after login

2. Introduce as needed

The above global import will package all echarts charts, causing the size to be too large. To solve this problem, I can use

requireIntroduce on demand, that is, import whatever is needed:

That is:

let echarts = require('echarts/lib/echarts')
Copy after login
3. Directly quote

globally in the index.html file, use the script tag to introduce

<script src="/static/js/echarts/echarts.js"></script>
Copy after login

Note: write in src The path of echarts;

Then find webpack.base.conf.js in the vue project build directory,

Configuration file, add the externals attribute to the module.exports object, and then configure The path where echarts is located:

module.exports = {
.....
externals: {
// 路径:命名空间
 'echarts/dist/echarts':'echarts',
}
};
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

The server directly obtains the file upload progress

How to use datepicker

Using ejsExcel template in Vue.js

The above is the detailed content of How to use echarts in Vue.JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template