// 获取“-”之前的字符串过滤器 let getHGbeforeStr = value =>{ if(!value) return '' if(value.search("-") !== -1){ return value.split("-").shift() } else { return '' } } // 获取“-”之后的字符串过滤器,数据示例 xxx-xxx let getHGlaterStr = value =>{ if(!value) return '' if(value.search("-") !== -1){ return value.split("-").pop() } else { return value } } export { getHGbeforeStr, getHGlaterStr }
main.js引入
import * as filters from '@/assets/js/filter' Object.keys(filters).forEach(key => { Vue.filter(key, filters[key]) })