• 动态绑定了静态class与动态class结合

      动态的class和静态的class结合 ```javascript :class=”[‘info-block’ ,index == 3 ? ‘afterborder’ :’’]”

    afterborder为class类名,要传指定的变量需要用:style

    1. - 动态绑定style样式
    2. ```javascript
    3. :style="isHide === true ? { display: 'none' } : {}"
    • computed写法

      1. bottomActive() {
      2. let barValue = ''
      3. this.bottomBar === true ? barValue = 100 : barValue = 0
      4. return `marginBottom: ${barValue}px`
      5. },
      6. 只能用到style
    • 获取屏幕滚动的距离

    注意好

    1. mounted() {
    2. // 滚动条的获取
    3. window.addEventListener('scroll', this.handleScroll, true)
    4. },
    5. methods: {
    6. handleScroll() {
    7. const a = document.getElementById('mainBox').scrollTop
    8. const switchValue = a > 200 ?this.isHide = true :this.isHide=false;
    9. // console.log(switchValue)
    10. // this.isHide = switchValue
    11. }
    12. }
    13. 销毁滚动条信息
    14. destroyed() {
    15. // 获取layout.vue的滚动区域的高度
    16. const dom = document.getElementById('mainBox')
    17. if (dom) {
    18. dom.removeEventListener('scroll', this.handleScroll)
    19. dom.scrollTop = 0
    20. }
    21. },

    span标签字体强制不换行

    1. white-space: nowrap; /*强制span不换行*/
    2. display: inline-block; /*将span当做块级元素对待*/
    3. width: 260px; /*限制宽度*/
    4. overflow: hidden; /*超出宽度部分隐藏*/
    5. text-overflow: ellipsis; /*超出部分以点号代替*/
    6. line-height: 0.9; /*数字与之前的文字对齐*/
    1. <text slot="icon" class="iconfont font-lg py-1">&#xe667;</text>
    2. <slot name="icon"></slot>
    1. // 获取屏幕信息
    2. getClientInfo() {
    3. var userAgentInfo = navigator.userAgent
    4. console.log(userAgentInfo)
    5. var Agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod']
    6. var agentinfo = null
    7. for (var i = 0; i < Agents.length; i++) {
    8. if (userAgentInfo.indexOf(Agents[i]) > 0) { agentinfo = userAgentInfo; break }
    9. }
    10. if (agentinfo) {
    11. console.log(agentinfo)
    12. return agentinfo
    13. } else {
    14. return 'PC'
    15. }
    16. }
    17. // 获取屏幕宽度判断
    18. const that = this
    19. window.onresize = () => {
    20. return (() => {
    21. window.screenWidth = document.body.clientWidth
    22. that.screenWidth = window.screenWidth
    23. })()
    24. }
    • 伪类元素扩大点击范围、
      1. .icon-box {
      2. position: relative;
      3. &::after {
      4. position: absolute;
      5. content: "";
      6. top: -5px;
      7. bottom: -5px;
      8. left: -5px;
      9. right: -5px;
      10. background-color: red;
      11. }
      12. }

    textarea自适应高度

    1. <template>
    2. <div class="my-textarea">
    3. <textarea ref="textarea" :style="{'height': height}" v-model="value" class="textarea" ></textarea>
    4. </div>
    5. </template>
    6. <script>
    7. import calcTextareaHeight from '@/assets/calcTextareaHeight';
    8. export default {
    9. name: 'my-textarea',
    10. data() {
    11. return {
    12. // textarea内容
    13. value: '',
    14. // 动态高度
    15. height: '30px'
    16. }
    17. },
    18. watch: {
    19. value() {
    20. this.getHeight();
    21. }
    22. },
    23. methods: {
    24. getHeight() {
    25. this.height = calcTextareaHeight(this.$refs.textarea, 1, null).height;
    26. }
    27. }
    28. }
    29. </script>
    30. <style scoped>
    31. .my-textarea .textarea {
    32. display: inline-block;
    33. width: 400px;
    34. /*height: 30px;*/
    35. line-height: 30px;
    36. font-size: 30px;
    37. resize: none;
    38. }
    39. </style>