npm install swiper后使用报错‘ Can't find variable: Dom7’

vue中使用swiper

import Swiper from 'swiper';




methods: {
    __init_swiper: function () {
        let swiper = new Swiper('#swiper_container', {
            autoplay: {
                disableOnInteraction: false,
                delay: 1000
            },
            pagination: {
                el: '.swiper-pagination',
                clickable: true
            },
        });
    }
},
mounted: function () {
    this.__init_swiper();
}

图片描述

package.json中的确是有dom7的
图片描述

我尝试着引入这个包,


    import Dom7 from 'dom7';
    import Swiper from 'swiper';

但没有任何效果,报的一样的错。

我知道可以在index.html中用<script>引入swiper,但现在我想只在这个component中引入。

could you please help me to solve this problem? or maybe there are any other way which can include the Swiper into the project? THANK Q.

阅读 4.4k
3 个回答

不能单文件组件用的原因往往是没封装成Vue插件的形式,我觉得你可以考虑用这个 - vue-awesome-swiper

有的是后就是包下的不完整 卸载之后再从新试一下 uninstall

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题