一、引入全局js
1.commonFunctions文件中新建common.js里面写上想全局调用的方法
2.main.js中importcommon from "../commonFunctions/common.js"引入文件
Vue.prototype.common= common;//挂载到原形上
3.组件中 this.common.a就可以使用啦
(需要注意的是公共文件引入后不能直接使用,必须在vue的原型链(prototype)里边注册,才可以使用。)
第二种:(使用filter)
1.main.js中
//过滤器
Vue.filter('formatAmount', function(amount) {
letfinalResult = ''
letj = 0
letstrAmount = amount.toString()
if(strAmount.indexOf('-') != '-1'){
strAmount = strAmount.slice(1);
for(leti = strAmount.length- 1; i >= 0; i--) {
//从末尾开始遍历到第一个
j++
finalResult = strAmount[i] + finalResult
if(strAmount[i] == '.') {
//逗号只加在整数部分
j = 0
}