【问题标题】:How to use intersection observer polyfill with Vue cli 3?如何在 Vue cli 3 中使用交叉点观察者 polyfill?
【发布时间】:2025-12-06 12:10:01
【问题描述】:

使用方法:https://github.com/w3c/IntersectionObserver/tree/master/polyfill

我应该将它加载到 webpack 配置 - vue.config.js 中还是应该使用导入将它加载到 .vue 模板中?

【问题讨论】:

  • 你发现了吗?我认为 vue-cli 内置的 babel/core-js 应该可以处理这个问题。
  • Intersection Observer 是浏​​览器独有的功能,core-js 中没有提供。 github.com/zloirock/core-js/issues/386

标签: vue.js intersection-observer


【解决方案1】:
npm install intersection-observer

将此行添加到您的条目文件的顶部(例如main.js

import 'intersection-observer/intersection-observer';

就是这样。

【讨论】: