在微信開發工具中運行文檔中的代碼,出現如下錯誤:
[渲染層錯誤] 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”。