练习日常

匹配换行符/n

<div v-html="formatArticleContent"></div>
  computed: {
    formatArticleContent () {
      if (this.article.content) {
        const reg = /\s/g
        return this.article.content.replace(reg, '<br>')
      }
      return true
    },
  },

split(',') 字符串分割成数组

  str.split(',')

超出隐藏 不换行 和禁用状态

  .banner .title {
    display: block;
    width: 100%;
    overflow: hidden; // 超出隐藏 不换行 省略
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-top: 10px;
    font-size: 12px;
    color: #707070;
  }

  .control .disabled {
    color: #707070;
        cursor: not-allowed; //禁用状态
  }

字符串截取

  filters: {
    sliceContent (value) {      
      return value.slice(0, 75) + '……'
    }
  }

缓存组件 key 监听路由改变

  <div>
    <yd-nav></yd-nav>
    <keep-alive>
      <router-view :key="$route.path"></router-view>
    </keep-alive>
  </div>

vue中window绑定事件

  //注意是否存在事件的冒泡
  created () {
    const _this = this
    document.addEventListener('click', function () {
      if (_this.show) {
        _this.show = false
      }
    })
  }

根据id过滤 得到想要的结果

一、.includes(user.id) 返回值 是true || false

//对users进行过滤
    state.users = state.users.filter(user => {
      return !ids.includes(user.id) //判断id不存在于当前数组ids中
    })

二、.find()返回值是 查找到的对象(true)或者 underfined (false)

    state.users = state.users.filter(user => {
      return !ids.find(id => id === user.id)
    })

三、数组过滤

var shopList=[
            {
                checked:true,
                shopName:'拼多多',
                goods:[
                    {
                        cart_code:'123',
                        cart_num:'10',
                        sku_name:'UT28364'
                    },
                    {
                        a:true,
                        cart_code:'123',
                        cart_num:'10',
                        sku_name:'UT28364'
                    },
                    {
                        a:true,
                        cart_code:'123',
                        cart_num:'10',
                        sku_name:'UT28364'
                    },
                ]
            },
            {
                checked:true,
                shopName:'美团',
                goods:[
                    {
                        cart_code:'123',
                        cart_num:'10',
                        sku_name:'UT28364'
                    },
                    {
                        a:true,
                        cart_code:'123',
                        cart_num:'10',
                        sku_name:'UT28364'
                    },
                ]
            },
        ]
shopList.forEach(item => {
item.goods = item.goods.filter(good => {
return good.a ===true
})
return item
});

oncontextmenu="return false" :禁止右键

<script type="text/javascript">
document.oncontextmenu=function(e){return false;};
document.onselectstart=function(e){return false;};
</script>

在页面的Body范围内,当触发客户端的ContextMenu事件时,返回false值,使右键不能弹出
如果需要额外处理的话,可以将return false写到其他的客户端脚本中,这样会更灵活

oncontextmenu="return false" :禁止右键

onselectstart="return false" : 禁止选取

onpaste = "return false" : 禁止粘贴

oncopy = "return false" : 禁止复制

oncut = "return false" : 禁止剪贴
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 概要 64学时 3.5学分 章节安排 电子商务网站概况 HTML5+CSS3 JavaScript Node 电子...
    阿啊阿吖丁阅读 9,694评论 0 3
  • 一:什么是闭包?闭包的用处? (1)闭包就是能够读取其他函数内部变量的函数。在本质上,闭包就 是将函数内部和函数外...
    xuguibin阅读 10,001评论 1 52
  • ## 经典bug:1.模板引擎的渲染## 难点:### 0.vue总结#### 指令:```jsVue.direc...
    x_ng阅读 329评论 0 0
  • 前言 你还记得2016年你给自己立下的目标吗?你现在回想起来有多少目标被实现?有多少停在半路?你还希望重复过去的故...
    领教CoachMax阅读 325评论 0 2
  • 上一章 【奇幻爱情】沉睡中的你(13) 文|大思思 图|网络 14 比生命更重要的事 尽管已经来过这个医院无数次了...
    彭西西阅读 262评论 0 1

友情链接更多精彩内容