vue.js - vue js component doesn't rerender on the same page -
i have component
<template>somecode</template> <script> export default { name: 'card', created() { axios.get(apiobjurl) somecode }) } </script>
this url: http://127.0.0.1:8080/#/card/12
but have problem:
when use router-link this:
<router-link to="/card/155"> card 155</router-link>
my url changes: http://127.0.0.1:8080/#/card/155
but created()
method doesn't fired. don't make new xhr request api , data not changes do?
that's because component created. may try using lifecycle hook updated()
instead of created()
.
export default { name: 'card', updated() { axios.get(apiobjurl) somecode }) }
note: work if dom changes. if want listen on url changes , update accordingly better $watch
route this.
export default { name: 'card', created() { axios.get(apiobjurl) somecode }), watch: { '$route': function() { // stuff here } } }
Comments
Post a Comment