如果使用 Internet Explorer.js则不要使用 Vue 导入模块



当我使用 vue-cli-service-build 构建我的 Vue.js 应用程序时,我在 Internet Explorer 上得到了一个空白页面(但它适用于 Firefox 和 Chrome(。我知道这个问题与CKEditor有关,因为它不受IE支持。但是,我创建了一个条件,如果我们不使用IE,则仅"需要"CKEditor。这个解决方案适用于 vue-cli-service-serve,但不适用于 vue-cli-service-build。

if(!usingIE())
{
alert("not using ieee");
CKEditor = require('@ckeditor/ckeditor5-vue').component;
ClassicEditor = require('@ckeditor/ckeditor5-build-classic');

}
else
{
alert("using IE");
}

如果我评论"需要"CKEditor模块并构建应用程序的两行,它适用于IE。

如果我在条件中输入 false 但没有注释这两行,它也适用于 IE。但是,这不是我想要的,因为我需要允许用户使用CKEditor,如果他们使用的是Chrome/Firefox。

if(false)
{
alert("not using ieee");
CKEditor = require('@ckeditor/ckeditor5-vue').component;
ClassicEditor = require('@ckeditor/ckeditor5-build-classic');
}

想知道我是否使用正确的方法来包含浏览器不支持的模块。否则,最好的方法是什么?

您可以尝试使用 v-if 和 v-else有条件地呈现组件。

例:

<div v-if="type === 'A'">
  A
</div>
<div v-else-if="type === 'B'">
  B
</div>
<div v-else-if="type === 'C'">
  C
</div>
<div v-else>
  Not A/B/C
</div>

引用:

(1( 条件渲染

(2( 条件组件渲染

(3( Vue.js 路由器 - 条件组件渲染

最新更新