ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] ### 1. 在组件文件中 给组件一个类名 tag-class ~~~ <view class="container tag-class"> <text>{{comment}}</text> <slot name="after"></slot> </view> ~~~ ### 2. 在组件的js中声明 ~~~ externalClasses: ['tag-class'], ~~~ ### 3. 父组件的json中注册 ~~~ { "usingComponents": { "v-tag":"/components/tag/index" } } ~~~ ### 4. 使用 将wxml传给子组件 通过相同的 tag-class ~~~ <v-tag comment="{{item.comment}}" tag-class="{{index==0?'bg':''||index==1?'bg1':''}}"> <text slot="after" class="num">+{{item.num}}</text> </v-tag> ~~~ ### 5. 设置css样式 ~~~ .bg{ background: #FFFADD !important ; } .bg1{ background: #EFFAFF !important ; } .like v-tag view:nth-child(1){ background: red ; } .like v-tag:nth-child(2)>view{ background: #EFFAFF ; } ~~~