代码之家  ›  专栏  ›  技术社区  ›  novalagung Alexander Kim

在VUE3项目中包括引导材料日期时间选择器

  •  0
  • novalagung Alexander Kim  · 技术社区  · 8 年前


    bootstrap-material-datetimepicker ,所以我在我的vue组件文件中导入了它。

    <template>
        <div>
            <!-- -->
        </div>
    </template>
    
    <script>
    // ..
    
    import 'bootstrap-material-datetimepicker/js/bootstrap-material-datetimepicker.js'
    import 'bootstrap-material-datetimepicker/css/bootstrap-material-datetimepicker.css'
    
    // ..
    </script>
    

    此第三方库需要jQuery。我把它加进去 vue.config.js

    const webpack = require('webpack')
    
    module.exports = {
        baseUrl: '/public/',
        plugins: [
            new webpack.ProvidePlugin({
                $: 'jquery',
                jquery: 'jquery',
                'window.jQuery': 'jquery',
                jQuery: 'jquery'
            })
        ]
    }
    

    命令行提示符上没有错误。但我确实在浏览器控制台上遇到了一些错误。

    vue router.esm.js?8c4f:1905 ReferenceError:未定义jQuery 评估时(引导材料datetimepicker.js?5260:1295) 在Object../node\u modules/bootstrap material datetimepicker/js/bootstrap-material-datetimepicker.js(vendors~PublicSignUp.js:76) 需要的网页包 在fn(附录js:131) 评估时(cjs.js)/node\u modules/babel loader/lib/index.js/节点\u modules/cache loader/dist/cjs.js/节点\u modules/vue loader/lib/index.js/src/pages/public/SignUp.vue?vue&类型=脚本;lang=js&:6) 在Module../node\u modules/cache loader/dist/cjs.js/node\u modules/babel loader/lib/index.js/节点\u modules/cache loader/dist/cjs.js/节点\u modules/vue loader/lib/index.js/src/pages/public/SignUp.vue?vue&类型=脚本;lang=js&(PublicSignUp.js:11) 在 需要的网页包 评估时(SignUp.vue?8585:1)

    有人能帮帮我吗?

    1 回复  |  直到 6 年前
        1
  •  1
  •   novalagung Alexander Kim    6 年前

    刚刚看到 similar issue on github 原来我只需要把 plugins configureWebpack .

    const webpack = require('webpack');
    
    module.exports = {
        baseUrl: '/public/',
        configureWebpack: {
            plugins: [
                new webpack.ProvidePlugin({
                    '$': 'jquery',
                    'jquery': 'jquery',
                    'jQuery': 'jquery',
                    'window.jQuery': 'jquery',
                    'moment': 'moment'
                })
            ]
        }
    }
    
    推荐文章