Bootstrap 5.x使用Modal报错:Uncaught TypeError: Cannot read properties of undefined (reading 'classList')
,那是由于使用的了jQuery,需要改一下写法。
原写法:
import Modal from 'bootstrap/js/src/modal'
if ($('#modalThemeBuy')) {
const modalThemeBuy = new Modal(document.getElementById('modalThemeBuy'));
$('#themeBuy').on('click', function () {
modalThemeBuy.show()
})
}
改为:
import Modal from 'bootstrap/js/src/modal'
if ($('#modalThemeBuy')) {
const modalThemeBuy = $('#modalThemeBuy');
$('#themeBuy').on('click', function () {
modalThemeBuy.show()
})
}