twbs / bootstrap

The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.
https://getbootstrap.com
MIT License
170.5k stars 78.84k forks source link

const myModal = document.getElementById('myModal') doesn't work #40613

Closed wei886-tw closed 3 months ago

wei886-tw commented 3 months ago

Prerequisites

Describe the issue

I'm using Vue3 "^3.4.21" and "bootstrap": "^5.3.3", and I'm using const myModal = document.getElementById('myModal') on mounted, but chrome devtool shows [Vue warn]: Unhandled error during execution of native event handler image

Reduced test cases

I used

const myModal = document.getElementById('myModal')
const myInput = document.getElementById('myInput')

myModal.addEventListener('shown.bs.modal', () => {
  myInput.focus()
})

but doesn't work

What operating system(s) are you seeing the problem on?

macOS

What browser(s) are you seeing the problem on?

Chrome

What version of Bootstrap are you using?

v5.3.3


Note: edited by maintainer for correct Markdown syntax

github-actions[bot] commented 3 months ago

Hello @wei886-tw. Bug reports must include a live demo of the issue. Per our contributing guidelines, please create a reduced test case on CodePen or StackBlitz and report back with your link, Bootstrap version, and specific browser and Operating System details.

Hichem-elAbassi commented 3 months ago

Can you try catch it just to see ?

wei886-tw commented 3 months ago

I useimport Modal from 'bootstrap/js/dist/modal'; solve the bug