Created
June 17, 2020 14:07
-
-
Save hipertracker/14b92c917afaa3254493dee19205ae89 to your computer and use it in GitHub Desktop.
Dynamic URL change: Quasar/Overmind + TypeScript + vue-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
<template> | |
<q-input clearable filled type="text" :value="q" @input="updateQuery" /> | |
</template> | |
<script lang="ts"> | |
import { defineComponent, ref, onMounted } from '@vue/composition-api'; | |
export default defineComponent({ | |
name: 'PageSearchInput', | |
setup(_props, { root: { $router, $route, actions, state } }) { | |
const q = ref($route.query.q); | |
onMounted(() => { | |
if (state.PageSearch.query.q) { | |
q.value = state.PageSearch.query.q; | |
$router.replace({ name: 'search', query: { q: q.value } }); | |
} | |
}); | |
function updateQuery(val: string) { | |
q.value = val; | |
$router.replace({ name: 'search', query: { q: val } }); | |
actions.PageSearch.updateQueryQ(val); | |
} | |
return { q, updateQuery }; | |
}, | |
}); | |
</script> |
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
<template> | |
<q-page padding> | |
<h1>Search</h1> | |
<PageSearchInput /> | |
</q-page> | |
</template> | |
<script lang="ts"> | |
import { defineComponent } from '@vue/composition-api'; | |
import PageSearchInput from 'components/PageSearchInput.vue'; | |
export default defineComponent({ | |
name: 'PageSearch', | |
components: { | |
PageSearchInput, | |
}, | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment