动态绑定了静态class与动态class结合
动态的class和静态的class结合 ```javascript :class=”[‘info-block’ ,index == 3 ? ‘afterborder’ :’’]”
afterborder为class类名,要传指定的变量需要用:style
- 动态绑定style样式```javascript:style="isHide === true ? { display: 'none' } : {}"
computed写法
bottomActive() {let barValue = ''this.bottomBar === true ? barValue = 100 : barValue = 0return `marginBottom: ${barValue}px`},只能用到style
获取屏幕滚动的距离
注意好
mounted() {// 滚动条的获取window.addEventListener('scroll', this.handleScroll, true)},methods: {handleScroll() {const a = document.getElementById('mainBox').scrollTopconst switchValue = a > 200 ?this.isHide = true :this.isHide=false;// console.log(switchValue)// this.isHide = switchValue}}销毁滚动条信息destroyed() {// 获取layout.vue的滚动区域的高度const dom = document.getElementById('mainBox')if (dom) {dom.removeEventListener('scroll', this.handleScroll)dom.scrollTop = 0}},
span标签字体强制不换行
white-space: nowrap; /*强制span不换行*/display: inline-block; /*将span当做块级元素对待*/width: 260px; /*限制宽度*/overflow: hidden; /*超出宽度部分隐藏*/text-overflow: ellipsis; /*超出部分以点号代替*/line-height: 0.9; /*数字与之前的文字对齐*/
父<text slot="icon" class="iconfont font-lg py-1"></text>子<slot name="icon"></slot>
// 获取屏幕信息getClientInfo() {var userAgentInfo = navigator.userAgentconsole.log(userAgentInfo)var Agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod']var agentinfo = nullfor (var i = 0; i < Agents.length; i++) {if (userAgentInfo.indexOf(Agents[i]) > 0) { agentinfo = userAgentInfo; break }}if (agentinfo) {console.log(agentinfo)return agentinfo} else {return 'PC'}}// 获取屏幕宽度判断const that = thiswindow.onresize = () => {return (() => {window.screenWidth = document.body.clientWidththat.screenWidth = window.screenWidth})()}
- 伪类元素扩大点击范围、
.icon-box {position: relative;&::after {position: absolute;content: "";top: -5px;bottom: -5px;left: -5px;right: -5px;background-color: red;}}
textarea自适应高度
<template><div class="my-textarea"><textarea ref="textarea" :style="{'height': height}" v-model="value" class="textarea" ></textarea></div></template><script>import calcTextareaHeight from '@/assets/calcTextareaHeight';export default {name: 'my-textarea',data() {return {// textarea内容value: '',// 动态高度height: '30px'}},watch: {value() {this.getHeight();}},methods: {getHeight() {this.height = calcTextareaHeight(this.$refs.textarea, 1, null).height;}}}</script><style scoped>.my-textarea .textarea {display: inline-block;width: 400px;/*height: 30px;*/line-height: 30px;font-size: 30px;resize: none;}</style>
