scoped一旦设置。那么该样式只能在当前组件中有效,因此有些样式是在组件内进行使用,因此直接设置是无效的
<template><div class="box"><!-- 九宫格区域 --><van-grid :column-num="3"><van-grid-item v-for="item in itemList" :key="item.url" :icon="item.url" :text="item.title" /></van-grid></div></template><style lang="less" scoped>.vant-grid{.van-icon__image{width:2em;height: 2em;}}</style>
以上的设置样式是无效的,因为图标所在的i标签并不在这个组件内,因此直接设置样式是无效的
这里采用样式穿透来解决
样式穿透:可以使得在当前组件设定样式,但是对当前组件的子组件一样有效。
在scss,less中一般使用/deep/
在**stylus**中一般使用>>>
.van-grid{/deep/ .van-icon__image{width:2em !important;height: 2em !important;}}
