Skip to content

Instantly share code, notes, and snippets.

@manakuro
Last active April 14, 2020 11:50
Show Gist options
  • Save manakuro/b40cc81aed1fb27ee385783b9acde339 to your computer and use it in GitHub Desktop.
Save manakuro/b40cc81aed1fb27ee385783b9acde339 to your computer and use it in GitHub Desktop.
<script lang="ts">
import {
computed,
defineComponent,
reactive,
watch
} from '@vue/composition-api'
import Logo from '~/components/Logo.vue'
export default defineComponent({
components: {
Logo
},
setup(_, ctx) {
const route = ctx.root.$route
const state = reactive({ route })
watch(
() => ctx.root.$route,
(r) => {
state.route = r as any
}
)
const myQuery = computed(() => state.route.query.myQuery)
const handleClick = (e: Event) => {
e.preventDefault()
ctx.root.$router.push({ query: { myQuery: 'handle my query!' } })
}
return {
myQuery,
handleClick
}
}
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment