Create a filters.js file.
import Vue from "vue"
Vue.filter("first4Chars", str => str.substring(0, 4))
Vue.filter("last4Chars", str => str.substring(str.length - 4))
Import it into your main.js.
import Vue from 'vue'
import App from './App'
import "./filters"
new Vue({
el: '#app',
template: '<App/>',
components: { App },
})
Here is a working example.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…