uniapp實現(xiàn)單選組件覆蓋選中樣式的方法
uniapp實現(xiàn)單選組件覆蓋選中樣式
完整代碼:
<!-- 是否選擇組件: trueOfFalseChooseBtn --> <template> <view class="is-true-body"> <view class="btn-con" :class="isTrue ? 'btn-con-active' : ''" @click="clickBtn(true)"> <text>是</text> </view> <view class="btn-con" :class="isTrue ? '' : 'btn-con-active'" @click="clickBtn(false)"> <text>否</text> </view> </view> </template> <script> export default { props: { value: { type: Boolean, default: true, }, }, watch: { isTrue(nv) { this.$emit('input', nv) } }, data() { return { isTrue: this.value, } }, methods: { clickBtn(e) { this.isTrue = e; } } } </script> <style lang="scss" scoped> .is-true-body { width: 100%; display: flex; justify-content: space-between; .btn-con { flex: 1; height: 40px; border-radius: 10px; text-align: center; line-height: 40px; position: relative; border: 1px solid rgba(255, 255, 255, 0); } .btn-con-active { border: 1px solid $uni-color-primary; } // 左上角三角形 .btn-con-active::after { content: ''; position: absolute; top: 0; left: 0; width: 0; height: 0; border-top: 28px solid $uni-color-primary; border-right: 30px solid rgba(255, 255, 255, 1); border-radius: 8px 0 0 0; } // 左上角勾勾圖片 .btn-con-active::before { content: url('@/static/images/icon/gg.svg'); position: absolute; top: -12px; left: 3px; width: 10px; height: 10px; z-index: 999; } } </style>
補(bǔ)充:
修改uniapp組件默認(rèn)樣式
最近使用uniapp開發(fā),有些組件渲染之后會生成一些標(biāo)簽,需要修改生成標(biāo)簽的樣式。比如
<uni-data-picker > 等組件,自定義類名還是加重權(quán)限均無法覆蓋原有樣式,解決辦法如下:
style標(biāo)簽上加scoped,同時類名前加/deep/ 穿透,即可覆蓋原有樣式
/deep/ .input-value-border{ border: none; }
到此這篇關(guān)于uniapp實現(xiàn)單選組件覆蓋選中樣式的文章就介紹到這了,更多相關(guān)uniapp內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

JAVASCRIPT實現(xiàn)的WEB頁面跳轉(zhuǎn)以及頁面間傳值方法