3👍
✅
Your code is not working because you are adding and removing in different MediaQueryList
objects.
...
mounted () {
this.mediaQueryList = window.matchMedia('(prefers-color-scheme: dark)')
this.$nextTick(() => {
this.mediaQueryList.addEventListener('change', this.setDarkMode)
})
},
beforeDestroy () {
this.mediaQueryList.removeEventListener('change', this.setDarkMode)
}
...
Source:stackexchange.com