gpt4 book ai didi

ruby-on-rails - Rails 6 + webpack 错误 : Uncaught TypeError: $(. ..).popover 不是函数

转载 作者:行者123 更新时间:2023-12-04 17:26:47 25 4
gpt4 key购买 nike

我正在 Rails 6 中开始一个新项目,这将是我第一次使用 Webpack,我在使用 时遇到了问题。弹窗 , 工具提示 , 下拉 .

application.js:37 Uncaught TypeError: $(...).dropdown is not afunction


environment.js
const { environment } = require('@rails/webpacker')

const webpack = require('webpack')
environment.plugins.append('Provide',
new webpack.ProvidePlugin({
$: 'jquery/src/jquery',
jQuery: 'jquery/src/jquery',
jquery: 'jquery',
'window.jQuery': 'jquery',
Popper: ['popper.js', 'default'],
Rails: ['@rails/ujs']
})
)

module.exports = environment
application.js
import 'core-js/stable'
import 'regenerator-runtime/runtime'

require("@rails/ujs").start()
require("turbolinks").start()
require("channels")

import 'bootstrap'
import './menu-left.cleanui-custom'
import './menu-right.cleanui-custom'
// Uncomment to copy all static images under ../images to the output folder and reference
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
// or the `imagePath` JavaScript helper below.
//
// const images = require.context('../images', true)
// const imagePath = (name) => images(name, true)

import '../stylesheets/application'


document.addEventListener("turbolinks:load", () => {
$('[data-toggle=popover-hover]').popover({
trigger: 'hover',
animation: false
});
$("[data-toggle=tooltip]").tooltip({
trigger: 'hover',
animation: false
});
});

$('.dropdown-toggle').dropdown();
错误从何而来?事实是我对 webpack 仍然很迷茫。

最佳答案

这对我有用:config/webpack/environment.js

const { environment } = require('@rails/webpacker')

const webpack = require('webpack')
environment.plugins.prepend('Provide',
new webpack.ProvidePlugin({
$: 'jquery/src/jquery',
jQuery: 'jquery/src/jquery',
Popper: ['popper.js', 'default']
})
)
environment.config.merge(
module.exports = {
resolve: {
alias: {
jquery: 'jquery/src/jquery',
}
}
}
)

module.exports = environment
app/javascript/packs/application.js
require("@rails/ujs").start()
require("turbolinks").start()
import "jquery"
import 'bootstrap'

document.addEventListener("turbolinks:load", function() {
$(function () {
$('[data-toggle="tooltip"]').tooltip()
$('[data-toggle="popover"]').popover()
})
})

关于ruby-on-rails - Rails 6 + webpack 错误 : Uncaught TypeError: $(. ..).popover 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62700600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com