西周舍利 2021-06-04 17:54 采纳率: 81.8%
浏览 41
已结题

angular启动项目,前端跨域问题怎么解决

import { Component, OnInit } from '@angular/core';
import * as echarts from 'echarts';
import 'echarts-gl';
import * as $ from 'jquery';

@Component({
  selector: 'app-echarts-glreal',
  templateUrl: './echarts-glreal.component.html',
  styleUrls: ['./echarts-glreal.component.scss']
})
export class EchartsGLRealComponent implements OnInit {

  ROOT_PATH = 'https://echarts.apache.org/examples';

  constructor() { }

  ngOnInit(): void {
    this.initChart();
  }

  initChart() {

    const ec = echarts as any;

    const echartReal3D = ec.init(document.getElementById('echartReal3D'));

    $.get(this.ROOT_PATH +'data/asset/data/life-expectancy-table.json', function (data) {
      echartReal3D.setOption({
        grid3D: {},
        xAxis3D: {},
        yAxis3D: {},
        zAxis3D: {},
        dataset: {
          source: data
        },
        series: [
          {
            type: 'scatter3D',
            symbolSize: 2.5
          }
        ]
      })
    });

  }
}
Access to XMLHttpRequest at 'https://echarts.apache.org/examples/data/asset/data/life-expectancy-table.json' from origin 'http://localhost:4200' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header has a value 'https://echarts.apache.org' that is not equal to the supplied origin.
echarts.apache.org/examples/data/asset/data/life-expectancy-table.json:1
Failed to load resource: net::ERR_FAILED
  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 系统已结题 10月6日
      • 已采纳回答 9月28日

      悬赏问题

      • ¥15 ABAQUS简单的带传动系统运转不了
      • ¥15 关于git actions自动部署的问题
      • ¥25 小程序 view wx:for 循环太多时,如何在循环结束执行某个事件?
      • ¥15 曲率模态差matlab程序计算
      • ¥15 大概算是比较简单的坐标系旋转问题
      • ¥15 关于#python#的问题:安装完gym环境后
      • ¥15 关于稳像云台姿态控制中相机姿态误差表征
      • ¥15 求sm16306s驱动例程
      • ¥15 本地生活媒体平台口碑选品怎么获得权限
      • ¥15 R语言 回归树/袋装树/随机森林预测