Skip to content

Commit 4437411

Browse files
committed
fix: remove more legacy support for vue 2
1 parent 323454b commit 4437411

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

src/runtime/plugin.client.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { computed, reactive, watch } from 'vue'
22

33
import type { ColorModeInstance } from './types'
4-
import { defineNuxtPlugin, isVue2, isVue3, useRouter, useHead, useState } from '#imports'
4+
import { defineNuxtPlugin, useRouter, useHead, useState } from '#imports'
55
import { globalName, storageKey, dataValue, disableTransition, storage } from '#color-mode-options'
66

77
type Helper = {
@@ -35,28 +35,13 @@ export default defineNuxtPlugin((nuxtApp) => {
3535
})).value
3636

3737
if (dataValue) {
38-
if (isVue3) {
39-
useHead({
40-
htmlAttrs: { [`data-${dataValue}`]: computed(() => colorMode.value) },
41-
})
42-
}
43-
else {
44-
const app = nuxtApp.nuxt2Context.app
45-
const originalHead = app.head
46-
app.head = function () {
47-
const head = (typeof originalHead === 'function' ? originalHead.call(this) : originalHead) || {}
48-
head.htmlAttrs = head.htmlAttrs || {}
49-
head.htmlAttrs[`data-${dataValue}`] = colorMode.value
50-
return head
51-
}
52-
}
38+
useHead({
39+
htmlAttrs: { [`data-${dataValue}`]: computed(() => colorMode.value) },
40+
})
5341
}
5442

5543
useRouter().afterEach((to) => {
56-
const forcedColorMode = isVue2
57-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
58-
? (to.matched[0]?.components.default as any)?.options.colorMode
59-
: to.meta.colorMode
44+
const forcedColorMode = to.meta.colorMode
6045

6146
if (forcedColorMode && forcedColorMode !== 'system') {
6247
colorMode.value = forcedColorMode

0 commit comments

Comments
 (0)