在Vue项目中如何使用其他插件(eCharts & wangeditor)

使用 echartys

1.使用其他插件 ,直接npm安装即可:

npm install echarts -S  //安装echarts依赖

这里写图片描述

2.创建图表,在 main.js 全局引入

import echarts from 'echarts'
Vue.prototype.$echarts = echarts

3.在需要使用 echarts 图表的地方 ,插入 html标签以及 js

<template>
    <div id="myChart" :style="{width: '1500px', height: '600px'}"></div>
</template>
<script>
    export default {
      mounted(){
        this.drawLine();
      },
      methods: {
        drawLine(){
            // 基于准备好的dom,初始化echarts实例
            let myChart = this.$echarts.init(document.getElementById('myChart'))
            // 绘制图表
            myChart.setOption({
                title: { text: '冬季销量统计' },
                tooltip: {},
                xAxis: {
                    data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子",'毛衣','秋裤','外套','短袖','手套','帽子','卫衣','棒球服']
                },
                yAxis: {},
                series: [{
                    name: '销量',
                    type: 'bar',
                    data: [5, 20, 36, 10, 10, 20,15,22,33,8,6,21,22,39]
                }]
            });
        }
      }
    }
</script>

这里写图片描述

使用wangeditor

1.使用 npm下载 :

npm install wangeditor --save   //(注意 wangeditor 全部是小写字母)

2.在需要的地方引入:

<template>
    <div>
        <div id="editorElem" style="text-align:left"></div>
    </div>  
</template>
<script>
 import E from 'wangeditor'
 export default {
      name: 'editor',
      data () {
        return {
          editorContent: ''
        }
      },
      mounted() {
        var editor = new E('#editorElem')
        editor.customConfig.onchange = (html) => {
          this.editorContent = html
        }
        editor.create()  
      }
    }
</script>

这里写图片描述

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Vue 使用高德地图和 echarts,需要先安装相应的依赖库。在命令行输入以下命令: ``` npm install echarts --save npm install echarts-gl --save npm install vue-amap --save ``` 安装完成后,可以在 Vue 组件使用这些库。以下是一个简单的示例: ```html <template> <div> <div ref="mapContainer" style="width: 100%; height: 400px;"></div> <div ref="chartContainer" style="width: 100%; height: 400px;"></div> </div> </template> <script> import VueAMap from 'vue-amap' import echarts from 'echarts' import 'echarts-gl' export default { name: 'MapChart', data() { return { map: null, chart: null, } }, mounted() { // 初始化高德地图 VueAMap.initAMapApiLoader({ key: 'YOUR_AMAP_KEY', plugin: ['AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.Geolocation'], v: '1.4.4', }) this.$nextTick(() => { this.map = new VueAMap.AMap.Map(this.$refs.mapContainer, { zoom: 14, center: [116.39, 39.9], }) }) // 初始化 echarts this.$nextTick(() => { this.chart = echarts.init(this.$refs.chartContainer) this.chart.setOption({ // echarts 配置 series: [ { type: 'bar3D', data: [...], }, ], }) }) }, } </script> ``` 在这个示例,我们通过 VueAMap 的 `initAMapApiLoader` 方法初始化了高德地图,并在 `mounted` 钩子函数创建了一个地图实例。同时,我们通过 echarts 的 `init` 方法初始化了一个图表,并在 `mounted` 钩子函数设置了图表的配置项。 需要注意的是,在 `mounted` 钩子函数创建地图和图表的实例时,需要使用 `this.$nextTick` 方法,以确保在组件渲染完毕后再进行初始化操作。 以上是一个简单的示例,具体的实现方式还需要根据具体的业务需求进行调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值