-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup composables for vue 2.7 (#9305)
* feat: setup vuelitdate for vue 2.7 * feat: add all composables * feat: return track method --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
- Loading branch information
Showing
6 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getCurrentInstance } from 'vue'; | ||
|
||
export const useTrack = () => { | ||
const vm = getCurrentInstance(); | ||
if (!vm) throw new Error('must be called in setup'); | ||
|
||
return vm.proxy.$track; | ||
}; | ||
|
||
export function useAlert(message, action) { | ||
bus.$emit('newToastMessage', message, action); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { getCurrentInstance, reactive, watchEffect } from 'vue'; | ||
|
||
/** | ||
* Returns the current route location. Equivalent to using `$route` inside | ||
* templates. | ||
*/ | ||
export function useRoute() { | ||
const instance = getCurrentInstance(); | ||
const route = reactive(Object.assign({}, instance.proxy.$root.$route)); | ||
watchEffect(() => { | ||
Object.assign(route, instance.proxy.$root.$route); | ||
}); | ||
|
||
return route; | ||
} | ||
|
||
/** | ||
* Returns the router instance. Equivalent to using `$router` inside | ||
* templates. | ||
*/ | ||
export function useRouter() { | ||
const instance = getCurrentInstance(); | ||
const router = instance.proxy.$root.$router; | ||
watchEffect(() => { | ||
if (router) { | ||
Object.assign(router, instance.proxy.$root.$router); | ||
} | ||
}); | ||
return router; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { computed } from 'vue'; | ||
import { getCurrentInstance } from 'vue'; | ||
|
||
export const useStore = () => { | ||
const vm = getCurrentInstance(); | ||
if (!vm) throw new Error('must be called in setup'); | ||
return vm.proxy.$store; | ||
}; | ||
|
||
export const useStoreGetters = () => { | ||
const store = useStore(); | ||
return Object.fromEntries( | ||
Object.keys(store.getters).map(getter => [ | ||
getter, | ||
computed(() => store.getters[getter]), | ||
]) | ||
); | ||
}; | ||
|
||
export const mapGetter = key => { | ||
const store = useStore(); | ||
return computed(() => store.getters[key]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters