解决:Some selectors are not allowed in component wxss, including tag name selectors, ID selectors

在微信开发工具中运行文档中的代码,出现如下错误:

 [渲染层错误] Some selectors are not allowed in component wxss, including tag name selectors, ID selectors, and attribute selectors.(./custom-tab-bar/index.wxss:36:15)(env: Windows,mp,1.06.2210310; lib: 2.5.0)

出现原因:随着小程序的发展,文档中原来的写法已经不受支持。官方文档也建议不再使用某些tag而换成新的写法。

解决方法:

第一步,把wxml文件里面要使用wxss的element都赋予一个类名

<cover-image src="{
   
   {selected === index ? item.selectedIconPath : item.iconPath}}"></cover-image>

改成

<cover-image class="tab-bar-item-image" src="{
   
   {selected === index ? item.selectedIconPath : item.iconPath}}"></cover-image>

 第二步,打开相应wxss文件,把里面的这种写法“.tab-bar-item cover-image”改成类名““.tab-bar-item-image””

如此这般把所有要用到wxss里面条目的element都改了。

第三步,把wxml文件中过时的“cover-view”和“cover-image”全部改成“view”和“image”。

猜你喜欢

转载自blog.csdn.net/K8001/article/details/127943008