Magento 2猫头鹰灵魂问题



在magento 2中,一段时间猫头鹰灵魂被加载或一段时间出现错误

$。((。猫头鹰灵魂不起作用。

Owlcarasol.js,包括前端的web/js和Required-config.js

items.html中的使用包含在设计/模板/item 中

调用时,有时owlCarousel未完全加载。

解决方案:

检查选择器是否存在,如果不存在,则等待500ms以满载。

<script type="text/javascript">
require(['jquery', 'domReady!', 'mageplaza/core/owl.carousel'], function ($) {
$(document).ready(function() {
'use strict';
if ($('#mp-list-items-<?= /** @noEscape */ $blockId ?>').length) {
setTimeout(() => {
$('#mp-list-items-<?= /** @noEscape */ $blockId ?>').owlCarousel(<?= /** @noEscape */ $block->getAllOptions()?>);
}, "500")
}
})
});
</script>

编辑:

您可以在布局页面上添加脚本,并像这样添加async属性。

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<script src="js/owl.carousel.min.js" async="async"/>
</head>
</page>

似乎也很有效

最新更新