解决uniapp微信小程序自定义组件/deep/、:v-deep 失效问题,亲测有效

1,163 阅读1分钟

问题描述:

  1. 使用uniapp开微信发小程序,A页面引入了B自定义组件(components/top/index)
  2. 我想要修改B自定义组件(components/top/index)中的第三方组件(uView)样式,然后使用了/deep/、:v-deep 都均不生效

问题解决:

我在B自定义组件(components/top/index)中,添加这段代码styleIsolation: 'shared'就可以解决了样式穿透的问题,如下:

    export default {
        data() {
            return {}
        },
        options: {
           styleIsolation: 'shared', // 解除样式隔离
        },
    }