echarts 、vue-cli整合粘贴指南

vue-cli 使用Echarts笔记

第一步、

npm install echarts --save

第二步、

​ webstrom中 main.js中

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-LzrWyySz-1595859574119)(/home/shaomin/.config/Typora/typora-user-images/image-20200701093656041.png)]

window.echarts = require('echarts')

(因为require是node.js属于后端语言,浏览器无法识别)

第三步、

<script></script>中:

var echarts = require('echarts'); // 基于准备好的dom,初始化echarts实例

var myChart = echarts.init(document.getElementById('main'));

``

第四步、

​ 粘贴、改数据

注:使用自己引入的封装好的js,方法如下:

	1. assets 目录下创建js目录,并导入Js文件

 		2. js文件末尾加入![image-20200701113808551](/home/shaomin/.config/Typora/typora-user-images/image-20200701113808551.png)
              		3. 页面script标签内直接引用(或者在index.html中直接引用)![image-20200701114754585](/home/shaomin/.config/Typora/typora-user-images/image-20200701114754585.png)

echarts 、vue-cli整合粘贴指南

  1. main.js

    // The Vue build version to load with the `import` command
    // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
    import Vue from 'vue'
    import App from './App.vue'
    import router from './router'
    import ElementUI from 'element-ui'
    import 'element-ui/lib/theme-chalk/index.css'
    import echarts from 'echarts'
    import axios from 'axios'
    import $ from 'jquery'
    
    
    Vue.config.productionTip = false
    Vue.use(ElementUI)
    Vue.use(echarts)
    Vue.prototype.$echarts = echarts
    Vue.prototype.$axios = axios;
    window.echarts = require('echarts')
    
    
    /* eslint-disable no-new */
    new Vue({
      el: '#app',
      router,
      components: { App },
      template: '<App/>',
    
    })
    
    
  2. xxx.vue

    drawPic1: function (){
                let myChartTwo= this.$echarts.init(document.getElementById('pic1'));//获得对象
                let option = {
                  xAxis: {
                    type: 'category',
                    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                  },
                  yAxis: {
                    type: 'value'
                  },
                  series: [{
                    data: [820, 932, 901, 934, 1290, 1330, 1320],
                    type: 'line'
                  }]
                };
                myChartTwo.setOption(option);//执行option
              },
              
    
    1. 注意变量、函数加载前后顺序

    2. 跨域问题(使用node跨域,因为node属于后端,不属于前端的跨域问题)

      在/config/index.js中

      proxyTable: {
            '/api': {
              target: 'http://localhost:8081/', // 设置你调用的接口域名和端口号
              changeOrigin: true,   // 跨域
              pathRewrite: {
                '^/api': '/'
              }
            }
          },
      
      1. 具体使用:相当于/api替代了http://localhost:8081/

        this.$axios.get("/api/company/selectMany?i=0&j=10").then(result => {
              this.tableData=result.data;
            }).catch((e) => { alert("wrong") })
        
        
        1. echarts 分为5个要点:

          定义一个有尺寸的div---->通过dom获得div对象—>在methods中加载粘贴过来的变量、方法、数据—>通过dom对象执行setOption(option),来画图

        注意事项:

        @click=“handleClick(scope.row)” 参数是把当前行当作一个对象传递

        this.$axios.get("/api/company/selectMany?i=0&j=10").then(result => {
          this.tableData=result.data;//result.data才能拿到数组,否则会报类型异常错误
        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值