前沿
這里是全局的設置,方便以后使用,做個筆記。
具體的設置全局組件和全局js請移步關于vue全局引用公共的js和公共的組件的折騰
首先,在你公共的文件夾下components
中新建一個文件夾,取名為commonJs,在里邊新建index.js
/**
* describe: 手機號中間四位顯示*
* name:愿醒靜臥忘塵谷
*/
export function starPhone(phoneNum){
let str = String(phoneNum),
strLen = str.slice(-7,-3);
return str.replace(strLen,"****");
}
/**
* describe: 數字千分位
* name:愿醒靜臥忘塵谷
*/
export function ThousandthPercentile(num) {
if (num === null) {
return num = 0;
} else {
if (num != undefined) {
return num = num.replace(/\d{1,3}(?=(\d{3})+(\.|$))/g, '$&,');
}
}
}
第一種:全局js ---------- 然后在main.js
中將這個js注冊到全局就可以了
{starPhone} 這里可以寫多個,使用逗號分隔開,具體看你commonJs里邊寫多少個方法了。
import {starPhone} from './components/index'
Vue.prototype.$starPhone = starPhone;
//然后在使用頁面直接this.$starPhone()引用就可以了。
第二種:單頁引用的js
<el-table-column
prop="merchantAvailableAmount"
:label="$t('language.finance.RemainingUnpaidUSD')" //做國際化的
align="center"
>
<template slot-scope="scope">
//這里是在頁面中直接使用
<span>{{ThousandthPercentile(scope.row.merchantAvailableAmount)}}</span>
</template>
</el-table-column>
import { ThousandthPercentile} from "@/components/index";
export default {
data() {
return {
};
},
methods:{
ThousandthPercentile,
}
}