Created
July 3, 2018 14:13
-
-
Save luiseok/407d74d483178c6a1ac117414d3f5e62 to your computer and use it in GitHub Desktop.
Vue.js bind URI query to computed
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> | |
<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