src/utils/index.ts
export const _scopeText = (str: string, len: number): string => {
if (str.length <= len) {
return str
}
return `${str.slice(0, len)}...`
}
export const _money = (number: number, mark: string): string => {
return `${mark}${number}`
}
main.ts
import { createApp } from 'vue'
import App from './App.vue'
import * as tools from './utils/index'
const app = createApp(App)
app.config.globalProperties.$filter = tools
app.mount('#app')
使用
<div>{{ $filter._scopeText(name, 10) }}</div>
<div>{{ $filter._scopeText(text, 30) }}</div>
<div>{{ $filter._money(33, '$') }}</div>