例えばuser一覧を表示する際に/user/allというurlを使用し、user.vueというcomponentで一覧を表示するとします。このcomponentは、/user/1とか/user/2といった各個人の情報を表示するケースでも再利用したいので、urlが変わる毎に同じcomponentにデータを再セットしようと挑戦しています。しかしこれが上手くいきません。
どなたかご教示頂けないでしょうか。
watchに$routeをセットしているので、私自身はここが変わればリロードが実行されると考えていたのですが、違うのでしょうか。
javascript
1// App.vue 2 3<template> 4... 5 <router-view 6 keep-alive 7 transition 8 transition-mode="out-in"> 9 </router-view> 10</template>
javascript
1// user.vue 2 3<template> 4 ... 5</template> 6 7<script> 8import user from './User.vue' 9import actions from './Actions.vue' 10... 11 12export default { 13 name: 'users', 14 components: { 15 user, 16 actions, 17 }, 18 data: function() { 19 return { 20 userList : [], 21 url : {} 22 } 23 }, 24 created() { 25 get(`/api/user/all`){ 26 // 27 } 28 }, 29 watch: { 30 '$route' (to, from) { 31 this.getContents() 32 } 33 }, 34 methods: { 35 getContents() { 36 get(this.url) 37 .then((res) => { 38 // 39 }) 40 .catch((err) => { 41 // 42 }) 43 } 44} 45</script>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/18 19:52