const code = this.params.replace(/(^\s*)|(\s*$)/g, "");vue
劃線部分取得是vue的data裏面的參數this
console.log(code);return;code
str爲要去除空格的字符串:
去除全部空格:
str = str.replace(/\s+/g,"");
去除兩頭空格:
str = str.replace(/^\s+|\s+$/g,"");
去除左空格:
str=str.replace( /^\s*/, '');
去除右空格:
str=str.replace(/(\s*$)/g, "");字符串