【问题标题】:Object.values() is not defined even when using shim即使使用 shim,也没有定义 Object.values()
【发布时间】:2018-06-13 08:23:32
【问题描述】:

我正在努力找出为什么不使用 Object.values 的垫片。错误监控不断引发类似这样的问题:

Object.values is not a function. (In 'Object.values(L)', 'Object.values' is undefined)

问题是我想我已经为不支持Object.values的浏览器提供了一个垫片:

// index.js

import 'es6-shim';
// ...


if (!Object.values) {
  require('object.values').shim();
}

global.App = {
  ...components,
  ...directives,
  ...mixins,
  ...filters,
  ...utils,
};

global.Vue = Vue;

global.ComponentsBootstrap = function ComponentsBootstrap(Vue) {
  if (process.env.NODE_ENV === 'production') {
    Raven
      .config('http://...')
      .addPlugin(RavenVue, Vue)
      .install()
    ;
  }

  const { provideComponents, provideDirectives, provideFilters } = global.App;

  Vue.use(provideComponents);
  Vue.use(provideDirectives);
  Vue.use(provideFilters);
};

代码的使用方式如下:

 <script src="dist/components/app.js"></script>

 <script>
     ComponentsBootstrap(Vue);
     // include other components that use `Object.values()`
 </script>

是不是因为 function ComponentsBootstrap 内部没有调用 require('object.values').shim() ?

【问题讨论】:

    标签: javascript ecmascript-6 shim


    【解决方案1】:

    在 IE11 中运行的一些 ES6 代码上使用 es6-shim 作为 polyfill 时,我也遇到了同样的问题。听起来 es6-shim 几乎没有 es7-shim 解决的差距,例如https://github.com/es-shims/es7-shim

    【讨论】:

      猜你喜欢
      • 2020-03-25
      • 1970-01-01
      • 2018-09-03
      • 2021-11-29
      • 1970-01-01
      • 2020-02-22
      • 1970-01-01
      • 2019-12-13
      • 1970-01-01
      相关资源
      最近更新 更多