We can create a plugin for this:
import Vue from 'vue'
export function truncate( text, length, suffix = '...' ) {
if (text.length > length) {
return text.substring(0, length) + suffix;
} else {
return text;
}
}
export function json( value ) {
return JSON.stringify(value);
}
const filters = { truncate, json }
Object.keys( filters ).forEach( key => {
Vue.filter( key, filters[ key ] )
})
then add this new plugin to the config
export default {
plugins: ['~/plugins/filters.js']
}
source
share