fix(tusimple-theme): clean up styles before unmount

This commit is contained in:
07akioni 2021-02-19 14:24:43 +08:00
parent 33810c1a9d
commit 5b7040a33d
2 changed files with 12 additions and 16 deletions

View File

@ -5,8 +5,7 @@ import {
defineComponent,
PropType,
provide,
reactive,
onBeforeMount
reactive
} from 'vue'
import { useMemo } from 'vooks'
import { warn, getSlot } from '../../_utils'
@ -41,7 +40,6 @@ export const configProviderProps = {
themeOverrides: Object as PropType<GlobalThemeOverrides | null>,
componentOptions: Object as PropType<ComponentProps>,
icons: Object as PropType<Icons>,
onBeforeMount: Function,
// deprecated
legacyTheme: String,
language: {
@ -132,10 +130,6 @@ export default defineComponent({
if (componentOptions !== undefined) return componentOptions
return NConfigProvider?.mergedComponentProps
})
onBeforeMount(() => {
const { onBeforeMount } = props
onBeforeMount?.()
})
provide<ConfigProviderInjection>(
'NConfigProvider',
reactive({

View File

@ -1,4 +1,4 @@
import { h, defineComponent } from 'vue'
import { h, defineComponent, onBeforeMount, onBeforeUnmount } from 'vue'
import { NConfigProvider, configProviderProps } from 'naive-ui'
import { renderFilter, renderSorter } from './data-table'
import { unconfigurableStyle, mountSvgDefs } from './unconfigurable-style'
@ -9,6 +9,15 @@ export default defineComponent({
name: 'TsConfigProvider',
props: configProviderProps,
setup () {
onBeforeMount(() => {
mountSvgDefs()
unconfigurableStyle.mount({
id: 'naive-ui/tusimple-theme'
})
})
onBeforeUnmount(() => {
unconfigurableStyle.unmount()
})
return {
componentOptions: {
Pagination: {
@ -27,13 +36,7 @@ export default defineComponent({
DynamicInput: {
buttonSize: 'small'
}
} as const,
onBeforeMount () {
mountSvgDefs()
unconfigurableStyle.mount({
id: 'naive-ui/tusimple-theme'
})
}
} as const
}
},
render () {
@ -43,7 +46,6 @@ export default defineComponent({
themeOverrides={themeOverrides}
componentOptions={this.componentOptions}
icons={icons}
onBeforeMount={this.onBeforeMount}
>
{this.$slots}
</NConfigProvider>