Skip to content

Instantly share code, notes, and snippets.

@luiseok
Created July 3, 2018 14:13
Show Gist options
  • Save luiseok/407d74d483178c6a1ac117414d3f5e62 to your computer and use it in GitHub Desktop.
Save luiseok/407d74d483178c6a1ac117414d3f5e62 to your computer and use it in GitHub Desktop.
Vue.js bind URI query to computed
<template>
<div>this is an exmaple of binding url query to vue.js computed property</div>
</template>
<script>
name: "example",
computed : {
page: {
get() {
//set default value here
var page = typeof this.$route.query.page !== 'undefined' ? this.$route.query.page : 0;
return page;
},
set(newPage) {
//set query string regex (ex-only digits, urlencode, etc) here
this.$router.push({ query: { page: newPage }})
}
}
}
</script>
<style>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment