• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
小码哥-倩倩
博客园    首页    新随笔    联系   管理    订阅  订阅

学习小收获笔记

1、vue中的watch监听数据的变化。

使用案例:监听手机号码,并且限制输入类型

<templete>
  <div>
    <input type="text" class="login-input float-lt" v-model="account" placeholder="请输入手机号">
  </div>
</templete>
watch:{
account(val){
let _this = this;
//监听登录的手机账号
if(this.account && this.account.length>11){
this.account = this.account.substring(0,11);
}
if(!(/^[0-9]*$/.test(this.account))){
let arr = this.account.split("");
var reg=/^[A-Za-z\u4E00-\u9FA5!!@#*&_\-/),./(,/(/)。/|\\]*$/;
arr.forEach((item,index)=>{
if(reg.test(item)){
_this.$set(_this,"account",_this.account.substring(0,index));
}
});
}
if(!(/^1[3|4|5|7|8|9][0-9]{9}$/.test(this.account))){
this.errorP = true;
}else{
this.errorP = false;
this.post.userAccount = _this.account;
}
this.post.userAccount = this.account
},
}

2、vue的filter过滤器实质不改变原始数据,只是对数据进行加工处理后返回过滤后的数据再进行调用处理,这点要切记

 

//利用filter截取字符串超过的使用。。。需要注意的是,这必须使用return,否则值就是空的
<template>
<div class="hello">
<p>filter{{info|filter1(10)}}</p>
</div>
</template>
filters:{
filter1:function(value,length){
let resault = value;
if(resault && resault.length>length){
resault = resault.substring(0,length);
resault = resault+'...';
}
return resault;
}
}



posted @ 2019-06-12 20:31  小码哥-倩倩  阅读(111)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3