Skip to content

Commit f15e2f7

Browse files
LinusBorgThorsten Luenborg
andauthored
feat(migration-guide): add global filters (#595)
migration strategy Co-authored-by: Thorsten Luenborg <t.luneborg@googlemail.com>
1 parent ab4fac3 commit f15e2f7

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/guide/migration/filters.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,31 @@ Using the example above, here is one example of how it could be implemented.
7272
## Migration Strategy
7373

7474
Instead of using filters, we recommend replacing them with computed properties or methods.
75+
76+
### Global Filters
77+
78+
If you are using filters that were globally registered and then used throughout our app, it's likely not convenient to replace them with computed props or methods in each individual component.
79+
80+
Instead, you can make your global filters available to all components through `app.globalProperties`:
81+
82+
```javascript
83+
// main.js
84+
const app = createApp(App)
85+
86+
app.config.globalProperties.$filters = {
87+
accountInUSD(num) {
88+
return '$' + num
89+
}
90+
}
91+
```
92+
93+
Then you can fix all templates using this `$filters` object like this:
94+
95+
```html
96+
<template>
97+
<h1>Bank Account Balance</h1>
98+
<p>{{ $filters.accountInUSD(accountInUSD) }}</p>
99+
</template>
100+
```
101+
102+
Note that with this approach, you can only use methods, not computed properties, as the latter only make sense when defined in the context of an individual component.

0 commit comments

Comments
 (0)