diff --git a/global.d.ts b/global.d.ts index d52dcf4..3060d36 100644 --- a/global.d.ts +++ b/global.d.ts @@ -9,8 +9,17 @@ declare module '*.scss' declare module '*.sass' declare module '*.styl' +// @ts-ignore +declare const process: { + env: { + TARO_ENV: 'weapp' | 'swan' | 'alipay' | 'h5' | 'rn' | 'tt', + [key: string]: any, + }, +} + declare namespace wx { interface ComponentOptions { addGlobalClass?: boolean, + styleIsolation?: 'isolated' | 'apply-shared' | 'shared' | 'page-isolated' | 'page-apply-shared' | 'page-shared', } } diff --git a/src/components/component.ts b/src/components/component.ts index cc47c9c..95ea70b 100644 --- a/src/components/component.ts +++ b/src/components/component.ts @@ -42,15 +42,16 @@ const component = < Overwrite, Overwrite > { - static options: wx.ComponentOptions = { - addGlobalClass: !disableGlobalClass, + static options: wx.ComponentOptions = disableGlobalClass ? {} : { + addGlobalClass: true, + styleIsolation: 'shared', } static defaultProps: P = props constructor() { super(...arguments) - if (Taro.getEnv() !== Taro.ENV_TYPE.WEB) { + if (process.env.TARO_ENV !== 'h5') { this.props = props as any } this.state = state as any