javascript - 为什么 ChartJs 不能在 IE 中运行

标签 javascript internet-explorer vue.js chart.js

本示例中的 VueJs 图表应用程序无法在 IE 中运行。有谁知道为什么吗?

例如下面的组件不打印错误但不同时运行

<div class="app">
    {{ message }}
  <line-chart></line-chart>
</div>


  Vue.component('line-chart', {
  extends: VueChartJs.Line,
  mounted () {
    this.renderChart({
      labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
      datasets: [
        {
          label: 'Data One',
          backgroundColor: '#f87979',
          data: [40, 39, 10, 40, 39, 80, 40]
        }
      ]
    }, {responsive: true, maintainAspectRatio: false})
  }

})

var vm = new Vue({
  el: '.app',
  data: {
    message: 'Hello World'
  }
})

最佳答案

这是因为,在您的组件中使用一种 ES6 语法来定义对象方法,在这一行:

mounted () {

... Internet Explorer 尚不支持 ES6 语法。

相反,如果您希望支持 IE,则必须在整个组件/应用程序中使用 ES5 语法:

Vue.component('line-chart', {
   extends: VueChartJs.Line,
   mounted: function() {  //<- use this instead
      this.renderChart({
         labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
         datasets: [{
            label: 'Data One',
            backgroundColor: '#f87979',
            data: [40, 39, 10, 40, 39, 80, 40]
         }]
      }, {
         responsive: true,
         maintainAspectRatio: false
      })
   }
});

查看working example .

关于javascript - 为什么 ChartJs 不能在 IE 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47069260/

相关文章:

vue.js - "unsupported type error"带有用于 .HDR 文件类型的 RGBE 加载器

javascript - 更新 DOM 中的子值

javascript - Vue.js 可排序列表 - 通过 AJAX 更新模型并保存更改位置

javascript - 以多个 selectInput 为条件的 conditionalPanel

javascript - 使用 setState 实时更新购物车商品

php - Div刷新和滚动条问题

internet-explorer - 在Powershell中使用IE COM对象自动从Web保存文件

php - 显示div的单个句子

html - IE 11 中的文件输入使同级 DIV 在单击或右键单击时消失

用于打开新窗口的 Javascript 代码在 IE 中不起作用