我妈已经三天没打我了 2022-04-20 14:06 采纳率: 85.4%
浏览 15
已结题

导入第三方库和插件起了冲突,用了等待加载的方式,但是报错了

报的错误是Error in nextTick: "ReferenceError: arr is not defined"
ReferenceError: arr is not defined



```bash

<template>
  <div>
    <div class="title">国内疫情地图</div>
    <!-- 地图容器 -->
    <van-tabs v-model="active" animated  @change="change">
      <van-tab title="现存确诊">
        <div id="nowmain" style="width: 7.5rem; height: 7rem"></div>
      </van-tab>
      <van-tab title="累计确诊">
        <div id="main" style="width: 7.5rem; height: 7rem"></div>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
// 引入接口
import api from "../api/index";
// 引入echarts
import echarts1 from "echarts";
// 引入地图echart中有
import "echarts/map/js/china";
export default {
  data() {
    return {
      active: 0,
      arr: [],
      nowarr:[],
    };
  },
  name: "Chinamap",
  // echarts实例-创建地图
  mounted() {
    // 生命周期去调用
    // this.getchart();
    api.getChinadata().then((res) => {
      console.log("国内地图数据", res.data);
      let citys = res.data.retdata;
      let arr = []; //累计
      let nowarr = []; //现存
      for (let i = 0; i < citys.length; i++) {
        let obj = {};
        obj.name = citys[i].xArea;
        obj.value = citys[i].confirm; //累计确诊人数
        arr.push(obj);
        let noe = {};
        noe.name = citys[i].xArea;
        noe.value = citys[i].curConfirm; //现存确诊人数
        nowarr.push(noe);
      }
      // 等待加载
      this.arr = arr;
      this.nowarr = nowarr;
      this.$nextTick(()=>{
        // 切换才能渲染
        // this.getchart(arr);
        this.getchart1(nowarr);
      }) 
      console.log("城市数据", arr);
      console.log("城市数据", nowarr);
    });
  },
  methods: {
    change(title){
      console.log("-----",title);
      if(title==1){
        this.$nextTick(()=>{
          this.getchart(arr);
        })
      }
    },
    getchart(data) {
      // 基于准备好的dom,初始化我查人太少实例
      var myChart = echarts1.init(document.getElementById("main"));
      // 指定图标的配置项和数据
      var option = {
        tooltip: {
          //悬浮弹框
          triggerOn: "click", //提示框触发的条件
          enterable: true, //鼠标是否可进入提示框浮层中,默认为false
          formatter(item) {
            //item=下面serves里面的data里面的每一项 //[{} ] data={} a b c d
            return (
              '<a href="#/citys/' +
              item.name +
              '" style="color:#fff">省份:' +
              item.name +
              "--详情</a>"
            );
          },
        },
        visualMap: [
          {
            //映射高亮颜色
            orient: "horizontal", //水平的
            type: "piecewise", //离散
            bottom: 0,
            textGap: 4,
            itemGap: 4,
            itemWidth: 10,
            itemHeight: 10,
            padding: 2,
            textStyle: {
              fontSize: 9,
            },
            pieces: [
              // 配置颜色区间
              {
                min: 0,
                max: 0,
                color: "#FFFFFF",
              },
              {
                min: 1,
                max: 9,
                color: "#FAEBD2",
              },
              {
                min: 10,
                max: 99,
                color: "#E9A188",
              },
              {
                min: 100,
                max: 499,
                color: "#D56355",
              },
              {
                min: 500,
                max: 999,
                color: "#BB3937",
              },
              {
                min: 1000,
                max: 10000,
                color: "#772526",
              },
              {
                min: 10000,
                color: "#480F10",
              },
            ],
          },
        ],
        series: [
          {
            name: "省",
            type: "map", //地图  bar  line  map
            map: "china", //中国地图 需要引入地图china.js
            roam: false,
            zoom: 1.2,
            aspectScale: 0.75,
            top: 40,
            layoutCenter: ["5%", "5%"],
            label: {
              normal: {
                show: true,
                textStyle: {
                  fontSize: 8,
                },
              },
            },
            itemStyle: {
              normal: {
                areaColor: "rgba(0,255,236,0)",
                borderColor: "rgba(0,0,0,0.2)",
              },
              emphasis: {
                // 选中的区域颜色及阴影效果等
                areaColor: "rgba(255,180,0,0.8)",
                shadowOffsetX: 0,
                shadowOffsetY: 0,
                shadowBlur: 20,
                borderWidth: 0,
              },
            },
            data,
          },
        ],
      };
      myChart.setOption(option);
    },
       getchart1(data) {
      // 基于准备好的dom,初始化我查人太少实例
      var myChart1 = echarts1.init(document.getElementById("nowmain"));
      // 指定图标的配置项和数据
      var option = {
        tooltip: {
          //悬浮弹框
          triggerOn: "click", //提示框触发的条件
          enterable: true, //鼠标是否可进入提示框浮层中,默认为false
          formatter(item) {
            //item=下面serves里面的data里面的每一项 //[{} ] data={} a b c d
            return (
              '<a href="#/citys/' +
              item.name +
              '" style="color:#fff">省份:' +
              item.name +
              "--详情</a>"
            );
          },
        },
        visualMap: [
          {
            //映射高亮颜色
            orient: "horizontal", //水平的
            type: "piecewise", //离散
            bottom: 0,
            textGap: 4,
            itemGap: 4,
            itemWidth: 10,
            itemHeight: 10,
            padding: 2,
            textStyle: {
              fontSize: 9,
            },
            pieces: [
              // 配置颜色区间
              {
                min: 0,
                max: 0,
                color: "#FFFFFF",
              },
              {
                min: 1,
                max: 9,
                color: "#FAEBD2",
              },
              {
                min: 10,
                max: 99,
                color: "#E9A188",
              },
              {
                min: 100,
                max: 499,
                color: "#D56355",
              },
              {
                min: 500,
                max: 999,
                color: "#BB3937",
              },
              {
                min: 1000,
                max: 10000,
                color: "#772526",
              },
              {
                min: 10000,
                color: "#480F10",
              },
            ],
          },
        ],
        series: [
          {
            name: "省",
            type: "map", //地图  bar  line  map
            map: "china", //中国地图 需要引入地图china.js
            roam: false,
            zoom: 1.2,
            aspectScale: 0.75,
            top: 40,
            layoutCenter: ["5%", "5%"],
            label: {
              normal: {
                show: true,
                textStyle: {
                  fontSize: 8,
                },
              },
            },
            itemStyle: {
              normal: {
                areaColor: "rgba(0,255,236,0)",
                borderColor: "rgba(0,0,0,0.2)",
              },
              emphasis: {
                // 选中的区域颜色及阴影效果等
                areaColor: "rgba(255,180,0,0.8)",
                shadowOffsetX: 0,
                shadowOffsetY: 0,
                shadowBlur: 20,
                borderWidth: 0,
              },
            },
            data,
          },
        ],
      };
      myChart1.setOption(option);
    },
  },
};
</script>

<style lang="scss" scoped></style>

```

  • 写回答

1条回答 默认 最新

  • 崽崽的谷雨 2022-04-20 14:20
    关注

    methods 里 change

    this.getchart(arr); arr 没定义 this.getchart(this.arr); 才对吧

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月30日
  • 已采纳回答 4月22日
  • 创建了问题 4月20日

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line