菜鳥教程javascript
<p>{{hidePhoneNum}}</p>
複製代碼
computed: {
hidePhoneNum() {
var phoneNum = this.$store.state.base.userInfo.phoneNum; //'18666667017'
return [phoneNum.substr(0, 3), '****', phoneNum.substr(-4, 4)].join(''); //'186****7017'
}
},
複製代碼
//let href = 'http://www.baidu.com/2018/07/16/moonsic#/data'
let href = window.location.href;
let hrefArray = href.split('/');
let uid = hrefArray[hrefArray.length-2].slice(0,-1);
this.id = uid;
複製代碼
let date = '2018-07-16';
let newDate = date.replace(/-/g, "");
this.date = newDate;
複製代碼
{{ word | limitWordCount(22) }}
filters:{
limitWordCount(val,num){
return val.length>num?val.substring(0,num)+'...':val;
}
}
複製代碼
先判斷是否爲字符串:html
if(typeof value == 'string'){
return substr(0,10)
}
if(typeof value != 'undefined'){
return value.substr(0,10);
}
複製代碼
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
var n=str.replaceAll("http","https");
複製代碼