Last active
June 15, 2020 02:05
-
-
Save hipertracker/ba6fff8e5ee2bfadc0758c341667444a to your computer and use it in GitHub Desktop.
Dynamic URL change: Quasar + TypeScript + vue-router
This file contains hidden or 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> | |
<b>Search</b> | |
<q-form> | |
<q-input filled type="text" :value="query" @input="updateQuery" /> | |
</q-form> | |
</q-page> | |
</template> | |
<script lang="ts"> | |
import VueRouter from 'vue-router'; | |
import { Route } from 'vue-router'; | |
import { defineComponent, ref } from '@vue/composition-api'; | |
function useQuery(router: VueRouter, route: Route) { | |
const query = ref(route.query.q); | |
function updateQuery(val: string) { | |
query.value = val; | |
router.replace({ name: 'main', query: { q: val } }); | |
} | |
return { query, updateQuery }; | |
} | |
export default defineComponent({ | |
name: 'DynamicQuery', | |
setup(_props, { root }) { | |
return { | |
...useQuery(root.$router, root.$route), | |
}; | |
}, | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment