vue绑定样式的方法
程序员文章站
2022-03-05 09:35:23
...
vue绑定样式的方法
一、绑定class
<div :class="[showIcon==='ios'?'active-btn':'','all-btn']" @click="changeCode('ios')">iPhone 下载</div>
<li :class="{ centerActive: isActive=='HomeDetail' }" @click="changePage('HomeDetail')">首页</li>
:class="[index==frameActive ? 'frame-item-active' : 'frame-item']"
二、绑定style
<div class="center-content" :style="{height:clientHeight-278+'px'}">
-
<div class="bar" :style="barStyle" /> barStyle: function () { return { left: `${this.x$ * 100}%` } },
-
areaStyle: function () { const style = { color: this.shadow, borderWidth: this.border + 'px', borderColor: this.borderColor, boxShadow: '0 0 0 ' + this._shadow, borderRadius: (this.round) ? '50%' : '' } this.ratio >= 1 ? (style.width = '50%') : (style.height = '50%') return style }
-
第四种是因为当时写了一个组件,然后颜色是从付组件可以传过来的,但是,因为有last-child所以才用了这种方法<div v-html="menuStyleText"></div> data(){ return{ menuStyleText:'' } } mounted(){ this.menuStyleText = `<style> .pass-input{ border: 1px solid ${this.linecolor ? this.linecolor : '#eeeeee'}; } .pass-input:last-child{ border-right: 1px solid ${this.linecolor ? this.linecolor + ' !important' : '#eeeeee !important'}; } } </style>`
上一篇: 递归思想在算法与数据结构中发挥到的作用
下一篇: HTML 样式