ã¬ã¤ã
åºæ¬çãªä½¿ãæ¹
- ã¤ã³ã¹ãã¼ã«
- ã¯ããã«
- Vue ã¤ã³ã¹ã¿ã³ã¹
- ãã³ãã¬ã¼ãæ§æ
- ç®åºããããã£ã¨ã¦ã©ããã£
- ã¯ã©ã¹ã¨ã¹ã¿ã¤ã«ã®ãã¤ã³ãã£ã³ã°
- æ¡ä»¶ä»ãã¬ã³ããªã³ã°
- ãªã¹ãã¬ã³ããªã³ã°
- ã¤ãã³ããã³ããªã³ã°
- ãã©ã¼ã å ¥åãã¤ã³ãã£ã³ã°
- ã³ã³ãã¼ãã³ãã®åºæ¬
ã³ã³ãã¼ãã³ãã®è©³ç´°
- ã³ã³ãã¼ãã³ãã®ç»é²
- ããããã£
- ã«ã¹ã¿ã ã¤ãã³ã
- ã¹ããã
- åç & éåæã³ã³ãã¼ãã³ã
- ç¹å¥ãªåé¡ã«å¯¾å¦ãã
ãã©ã³ã¸ã·ã§ã³ã¨ã¢ãã¡ã¼ã·ã§ã³
- Enter/Leave ã¨ãã©ã³ã¸ã·ã§ã³ä¸è¦§
- ç¶æ ã®ãã©ã³ã¸ã·ã§ã³
åå©ç¨ã¨æ§æ
- ããã¯ã¹ã¤ã³
- ã«ã¹ã¿ã ãã£ã¬ã¯ãã£ã
- æç»é¢æ°ã¨JSX
- ãã©ã°ã¤ã³
- ãã£ã«ã¿ã¼
ãã¼ã«
- åä¸ãã¡ã¤ã«ã³ã³ãã¼ãã³ã
- ãã¹ã
- TypeScript ã®ãµãã¼ã
- ãããã¯ã·ã§ã³ç°å¢ã¸ã®é ä¿¡
ã¹ã±ã¼ã«ã¢ãã
- ã«ã¼ãã£ã³ã°
- ç¶æ 管ç
- ãµã¼ããµã¤ãã¬ã³ããªã³ã°
- ã»ãã¥ãªãã£
å é¨
- ãªã¢ã¯ãã£ãã®æ¢æ±
移è¡
- Vue 1.x ããã®ç§»è¡
- Vue Router 0.7.x ããã®ç§»è¡
- Vuex 0.6.x ãã 1.0 ã¸ã®ç§»è¡
ãã®ä»
- ä»ã®ãã¬ã¼ã ã¯ã¼ã¯ã¨ã®æ¯è¼
- Vue.js ã³ãã¥ããã£ã¸åå ãã¾ããã!
- ãã¼ã ã«ä¼ãã
v2.x 以åã®ããã¥ã¡ã³ãã§ãã v3.x ã®ããã¥ã¡ã³ããè¦ããå ´åã¯ãã¡ã
Vue Router 0.7.x ããã®ç§»è¡
æçµæ´æ°æ¥: 2019å¹´5æ8æ¥
Vue Router 2.0 㯠Vue 2.0 ã«å¯¾å¿ããå¯ä¸ã®ã«ã¼ã¿ãªã®ã§ã Vue ãæ´æ°ããå ´åã«ã¯ Vue Router ãåæ§ã«æ´æ°ããå¿ è¦ãããã¾ãã2.0 ã®ããã¥ã¡ã³ãã«ç§»è¡ã¬ã¤ããç¨æããã¦ããã®ãããããçç±ããã§ããæ°ãã Vue Router ãç¨ããå æ¬çãªããã¥ã¡ã³ã㯠Vue Router ããã¥ã¡ã³ãã確èªãã¦ãã ããã
ã«ã¼ã¿ã®åæå
router.start
ç½®ãæã
Vue Router ã§ã¢ããªã±ã¼ã·ã§ã³ãåæåããããã®ç¹å¥ãª API ã¯ãªããªãã¾ããã以ä¸ã®ä»£ããã«:
router.start({
template: '<router-view></router-view>'
}, '#app')
Vue ã¤ã³ã¹ã¿ã³ã¹ã« router ããããã£ã渡ãã ãã§ã:
new Vue({
el: '#app',
router: router,
template: '<router-view></router-view>'
})
ã¾ãã¯ãVue ã®ã©ã³ã¿ã¤ã ã®ã¿ã®ãã«ãã使ç¨ãã¦ããå ´åã¯:
new Vue({
el: '#app',
router: router,
render: h => h('router-view')
})
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã router.start
ãã³ã¼ã«ãããç®æãæ¤åºãã¦ãã ããã
ã«ã¼ãã®å®ç¾©
router.map
ç½®ãæã
ã«ã¼ã㯠routes
ãªãã·ã§ã³ ã«é
åã¨ãã¦å®ç¾©ãããããã«ãªãã¾ãããä¾ãã°ãã®ãããªã«ã¼ãã®è¨è¿°ã¯:
router.map({
'/foo': {
component: Foo
},
'/bar': {
component: Bar
}
})
ãã®ããã«è¨è¿°ããããã«ãªãã¾ã:
var router = new VueRouter({
routes: [
{ path: '/foo', component: Foo },
{ path: '/bar', component: Bar }
]
})
ãªãã¸ã§ã¯ãã®å復走æ»ã¯ããããã£ã®é åºã«ãã©ã¦ã¶æ¯ã®ä¸è²«æ§ããªããããé åã«ããè¨æ³ãç¨ãããã¨ã§ãããäºæ¸¬å¯è½ãªã«ã¼ãã®ãããã³ã°ãå®ç¾ãã¦ãã¾ãã
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã router.map
ãã³ã¼ã«ãããç®æãæ¤åºãã¦ãã ããã
router.on
åé¤
ã¢ããªã±ã¼ã·ã§ã³ã®éå§æã«ãæ©æ¢°çã«ã«ã¼ããçæããå¿ è¦ãããå ´åãã«ã¼ãã®é åã«å¯¾ãåçã«å®ç¾©ã追å ãããã¨ãã§ãã¾ããä¾ãã°æ¬¡ã®ãããªå½¢ã§ã:
// é常ã®ã«ã¼ãå®ç¾©
var routes = [
// ...
]
// åçã«çæãããã«ã¼ãå®ç¾©
marketingPages.forEach(function (page) {
routes.push({
path: '/marketing/' + page.slug
component: {
extends: MarketingComponent
data: function () {
return { page: page }
}
}
})
})
var router = new Router({
routes: routes
})
ã«ã¼ã¿ãåæåãããå¾ã«æ°ããã«ã¼ãã追å ããå¿ è¦ãããå ´åãå çãããæ°ããã«ã¼ãæ©æ§ã§ãæ¢åã®ãã®ãç½®ãæãããã¨ãã§ãã¾ãã
router.match = createMatcher(
[{
path: '/my/new/path',
component: MyComponent
}].concat(router.options.routes)
)
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã移è¡ãã«ãã¼ ãå®è¡ã router.on
ãã³ã¼ã«ãããç®æãæ¤åºãã¦ãã ããã
router.beforeEach
å¤æ´
router.beforeEach
ã¯ç¾å¨éåæã«åä½ãã3çªç®ã®å¼æ°ã¨ã㦠next
é¢æ°ãåãã¾ãã
router.beforeEach(function (transition) {
if (transition.to.path === '/forbidden') {
transition.abort()
} else {
transition.next()
}
})
router.beforeEach(function (to, from, next) {
if (to.path === '/forbidden') {
next(false)
} else {
next()
}
})
subRoutes
ååå¤æ´
Vue ã¨ä»ã®ã«ã¼ã¿ã©ã¤ãã©ãªã¨ã®ä¸è²«æ§ã®ããã«ãchildren
ã«ååãå¤æ´ããã¾ããã
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã移è¡ãã«ãã¼ ãå®è¡ã subRoutes
ãã³ã¼ã«ãããç®æãæ¤åºãã¦ãã ããã
router.redirect
ç½®ãæã
ã«ã¼ãå®ç¾©ã«ããããªãã·ã§ã³ ã¨ãã¦è¨è¿°ããããã«ãªãã¾ããããã£ã¦ãä¾ãã°æ¬¡ã®ãããªä¾ã¯:
router.redirect({
'/tos': '/terms-of-service'
})
routes
è¨å®å
ã«ã¦æ¬¡ã®ããã«è¨è¿°ãã¾ã:
{
path: '/tos',
redirect: '/terms-of-service'
}
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã移è¡ãã«ãã¼ ãå®è¡ãrouter.redirect
ãã³ã¼ã«ãããç®æãæ¤åºãã¦ãã ããã
router.alias
ç½®ãæã
ã«ã¼ãå®ç¾©ã«ããããªãã·ã§ã³ ã¨ãã¦è¨è¿°ããããã«ãªãã¾ããããã£ã¦ãä¾ãã°æ¬¡ã®ãããªä¾ã¯:
router.alias({
'/manage': '/admin'
})
routes
è¨å®å
ã«ã¦æ¬¡ã®ããã«è¨è¿°ãã¾ã:
{
path: '/admin',
component: AdminPanel,
alias: '/manage'
}
è¤æ°ã®ã¨ã¤ãªã¢ã¹ãå¿ è¦ãªå ´åãé åè¨æ³ãç¨ãããã¨ãã§ãã¾ãã
alias: ['/manage', '/administer', '/administrate']
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã router.alias
ãã³ã¼ã«ãããç®æãæ¤åºãã¦ãã ããã
ä»»æã®ã«ã¼ããããã㣠置ãæã
å°æ¥ã®æ©è½ã¨ã®ç«¶åãé¿ããããã«ãä»»æã®ã«ã¼ãããããã£ã®ã¹ã³ã¼ããæ°ããã¡ã¿ããããã£ã®ä¸ã«è¨å®ããå¿ è¦ãããã¾ããä¾ãã°ã次ã®ããã«å®ç¾©ããã¨ãã¾ã:
'/admin': {
component: AdminPanel,
requiresAuth: true
}
次ã«ãããã次ã®ããã«æ´æ°ãã¾ã:
{
path: '/admin',
component: AdminPanel,
meta: {
requiresAuth: true
}
}
ãã®å¾ãã«ã¼ãä¸ã§ãã®ããããã£ã«ã¢ã¯ã»ã¹ããã¨ãã¡ã¿ãééãã¾ããä¾ãã°:
if (route.meta.requiresAuth) {
// ...
}
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ã¬ã¤ã ãå®è¡ãã¡ã¿ã®ä¸ã§ã¹ã³ã¼ããããªãä»»æã®ã«ã¼ãããããã£ãå©ç¨ãã¦ããç®æãæ¤åºãã¦ãã ããã
[]ã¯ã¨ãªå é åã®ããã®æ§æ åé¤
ã¯ã¨ãªãã©ã¡ã¼ã¿ã«é
åã渡ãã¨ã QueryString ã®æ§æã¯ãã¯ã /foo?users[]=Tom&users[]=Jerry
ã§ã¯ãªãããã®ä»£ãããæ°ããæ§æ㯠/foo?users=Tom&users=Jerry
ã¨ãªãã¾ããã å
é¨çã«ã¯ã $route.query.users
ã¯ä»¥åã¨ãã¦é
åã§ããã ããã¯ã¨ãªå
ã«ãã©ã¡ã¼ã¿ã1åã§: /foo?users=Tom
ããã®ã«ã¼ãã«ç´æ¥ã¢ã¯ã»ã¹ããã¨ããã«ã¼ã¿ã¯ users
ãé
åã¨ãã¦æå¾
ãã¦ãããã©ãããç¥ãæ¹æ³ãããã¾ããããã®ãããç®åºããããã£ã追å ãã $route.query.users
ã®å
¨ã¦ã®åç
§ãããã«ç½®ãæãããã¨ãæ¤è¨ãã¦ãã ãã:
export default {
// ...
computed: {
// users ã¯å¸¸ã«é
åã¨ãªãã¾ã
users () {
const users = this.$route.query.users
return Array.isArray(users) ? users : [users]
}
}
}
ã«ã¼ãã®ãããã³ã°
ããæè»æ§ãé«ããããã«ãã«ã¼ãã®ãããã³ã°ã®å é¨å¦çã«ã¯ã path-to-regexp ãå©ç¨ãããããã«ãªãã¾ããã
1ã¤ä»¥ä¸ã®ååä»ããã©ã¡ã¼ã¿
æ§æã«å¤å°ã®å¤åãããã¾ããä¾ãã° /category/*tags
㯠/category/:tags+
ã«å¤æ´ããå¿
è¦ãããã¾ãã
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ã¬ã¤ã ãå®è¡ãå»æ¢ãããææ³ãå©ç¨ãã¦ããç®æãæ¤åºãã¦ãã ããã
ãªã³ã¯
v-link
ç½®ãæã
Vue 2.0 ã«ãããã³ã³ãã¼ãã³ãã®æ©è½ã®ä¸ç°ã¨ãã¦ãv-link
ãã£ã¬ã¯ãã£ãã¯æ°ãã <router-link>
ã³ã³ãã¼ãã³ã ã«ç½®ãæãããã¾ããã以ä¸ã®ãããªå½¢ã§è¨è¿°ããããªã³ã¯ã¯:
<a v-link="'/about'">About</a>
次ã®ããã«å¤æ´ããªããã°ãªãã¾ãã:
<router-link to="/about">About</router-link>
<router-link>
ã§ã¯ target="_blank"
ã¯ãµãã¼ãããããªããã¨ã«æ³¨æãã¦ãã ãããæ°ããã¿ãã§ãªã³ã¯ãéãå¿
è¦ãããå ´åã¯ã<a>
ã代ããã«ä½¿ç¨ããªããã°ãªãã¾ããã
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã v-link
ãã£ã¬ã¯ãã£ãã使ç¨ããã¦ããç®æãæ¤åºãã¦ãã ããã
v-link-active
ç½®ãæã
<router-link>
ã³ã³ãã¼ãã³ã ã§ã¿ã°ã®æå®ãå¯è½ãªããã v-link-active
ãã£ã¬ã¯ãã£ãã¯å»æ¢ããã¾ããããã£ã¦ãä¾ãã°æ¬¡ã®ãããªä¾ã¯:
<li v-link-active>
<a v-link="'/about'">About</a>
</li>
ãã®ãããªå½¢ã«ãªãã¾ã:
<router-link tag="li" to="/about">
<a>About</a>
</router-link>
<a>
ãå®éã®ãªã³ã¯ã¨ãªã (æ£ãã href ããã£ã¦ãã¾ã), active ã¯ã©ã¹ã¯å¤å´ã® <li>
ã«ä»ä¸ããã¾ãã
移è¡ã¬ã¤ã
ã³ã¼ãä¸ã§ 移è¡ã¬ã¤ã ãå®è¡ã v-link-active
ãã£ã¬ã¯ãã£ãã使ç¨ããã¦ããç®æãæ¤åºãã¦ãã ããã
åçãªããã²ã¼ã·ã§ã³
router.go
å¤æ´
HTML5 History API ã¨ä¸è²«æ§ãä¿ã¤ããã«ãrouter.go
ã¯æ»ã/é²ãããã²ã¼ã·ã§ã³ã®ããã«ä½¿ç¨ããã¾ããrouter.push
ã¯ç¹å®ã®ãã¼ã¸ã«ç§»åããããã«ä½¿ç¨ããã¾ãã
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã router.push
ã®ä»£ããã«ä½¿ç¨ããã router.go
ãã³ã¼ã«ãããç®æãæ¤åºãã¦ãã ããã
ã«ã¼ã¿ãªãã·ã§ã³: ã¢ã¼ã
hashbang: false
åé¤
Google ã«URL ãã¯ãã¼ã«ãããããã« Hashbangs ãç¨ããå¿ è¦ã¯ãã¯ããªããªãã¾ããããã£ã¦ããã·ã¥ã®æ¹å¼ã¨ãã¦ããã©ã«ãã§ã¯ãªããªãããªãã·ã§ã³ã¨ãã¦å©ç¨ã§ããªããªãã¾ããã
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã hashbang: false
ãªãã·ã§ã³ãå©ç¨ããã¦ããç®æãæ¤åºãã¦ãã ããã
history: true
ç½®ãæã
ã«ã¼ãã£ã³ã°ã®åä½ã«é¢ãããªãã·ã§ã³ã¯ mode
ãªãã·ã§ã³ ã«ã¾ã¨ãããã¾ããããã®ãããªè¨è¿°ã¯:
var router = new VueRouter({
history: 'true'
})
次ã®ããã«å¤æ´ããªããã°ãªãã¾ãã:
var router = new VueRouter({
mode: 'history'
})
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã history: true
ãªãã·ã§ã³ã使ç¨ããã¦ããç®æãæ¤åºãã¦ãã ããã
abstract: true
ç½®ãæã
ã«ã¼ãã£ã³ã°ã®åä½ã«é¢ãããªãã·ã§ã³ã¯ mode
ãªãã·ã§ã³ ã«ã¾ã¨ãããã¾ããããã®ãããªè¨è¿°ã¯:
var router = new VueRouter({
abstract: 'true'
})
次ã®ããã«å¤æ´ããªããã°ãªãã¾ãã:
var router = new VueRouter({
mode: 'abstract'
})
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã abstract: true
ãªãã·ã§ã³ã使ç¨ããã¦ããç®æãæ¤åºãã¦ãã ããã
ãã®ä»ã®ã«ã¼ããªãã·ã§ã³
saveScrollPosition
ç½®ãæã
é¢æ°ãåãä»ãã scrollBehavior
ãªãã·ã§ã³ ã«å¤æ´ããã¾ãããã¹ã¯ãã¼ã«ã®æåã¯ãã«ã¼ããã¨ã«å®å
¨ã«ã«ã¹ã¿ãã¤ãºå¯è½ã«ãªãã¾ãããããã«ãã£ã¦ããå¤ãã®å¯è½æ§ãã²ãããã¾ããããåã«ä»¥åã®æåãåç¾ãããå ´åãããã§ããããããã¾ã§ã次ã®ããã«è¨è¿°ãã¦ããæã¯:
saveScrollPosition: true
ãã®ããã«å¤æ´ããã°ãåãåä½ãä¿ããã¾ã:
scrollBehavior: function (to, from, savedPosition) {
return savedPosition || { x: 0, y: 0 }
}
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã saveScrollPosition: true
ãªãã·ã§ã³ã使ç¨ãã¦ããç®æãæ¤åºãã¦ãã ããã
root
ååå¤æ´
HTML ã® <base>
è¦ç´ ã¨åããããã base
ã«å称å¤æ´ããã¾ããã
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã root
ãªãã·ã§ã³ã使ç¨ãã¦ããç®æãæ¤åºãã¦ãã ããã
transitionOnLoad
åé¤
Vue ã®ãã©ã³ã¸ã·ã§ã³æ©è½ã«ãappear
ãã©ã³ã¸ã·ã§ã³ã®å¶å¾¡ ãå®è£
ãããããããã®ãªãã·ã§ã³ã¯ãã¯ãä¸è¦ã«ãªãã¾ããã
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã transitionOnLoad: true
ãªãã·ã§ã³ã使ç¨ãã¦ããç®æãæ¤åºãã¦ãã ããã
suppressTransitionError
åé¤
ããã¯ãããã·ã³ãã«ã«ããããã«åé¤ããã¾ãããã©ããã¦ããã©ã³ã¸ã·ã§ã³ã®ã¨ã©ã¼ãæå¶ããªããã°ãªããªãå ´å try
â¦catch
æ§æã代ããã«ä½¿ç¨ãã¦ãã ããã
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã suppressTransitionError: true
ãªãã·ã§ã³ã使ç¨ãã¦ããç®æãæ¤åºãã¦ãã ããã
ã«ã¼ãããã¯
activate
ç½®ãæã
代ããã«ã³ã³ãã¼ãã³ãã«ã¦ beforeRouteEnter
ã使ç¨ãã¦ãã ããã
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã activate
ããã¯ã使ç¨ãã¦ããç®æãæ¤åºãã¦ãã ããã
canActivate
ç½®ãæã
代ããã«ãã«ã¼ãå
㧠beforeEnter
ã使ç¨ãã¦ãã ããã
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã canActivate
ããã¯ã使ç¨ãã¦ããç®æãæ¤åºãã¦ãã ããã
deactivate
åé¤
代ããã«ãã³ã³ãã¼ãã³ãã«ã¦ beforeDestroy
ã使ç¨ããã destroyed
ããã¯ã使ç¨ããããã«ãã¦ãã ããã
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã deactivate
ããã¯ã使ç¨ãã¦ããç®æãæ¤åºãã¦ãã ããã
canDeactivate
åé¤
代ããã«ãã³ã³ãã¼ãã³ãå
㧠beforeRouteLeave
ã使ç¨ãã¦ãã ããã
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã canDeactivate
ããã¯ã使ç¨ãã¦ããç®æãæ¤åºãã¦ãã ããã
canReuse: false
åé¤
æ°ãã Vue Router ã§ã¯ããã使ç¨ããå ´é¢ã¯ç¡ãã§ãããã
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã canReuse: false
option.
data
ç½®ãæã
$route
ããããã£ã¯å¸¸ã«ãªã¢ã¯ãã£ããªãããã«ã¼ãã®å¤æ´ã¯æ¬¡ã®ããã«ã¦ã©ããæ©è½ãå©ç¨ããäºã§æ¤åºã§ãã¾ã:
watch: {
'$route': 'fetchData'
},
methods: {
fetchData: function () {
// ...
}
}
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã data
ããã¯ã使ç¨ãã¦ããç®æãæ¤åºãã¦ãã ããã
$loadingRouteData
åé¤
ç¬èªã®ããããã£ãå®ç¾©ã (ä¾ãã° isLoading
), ã«ã¼ãã®ã¦ã©ããã£ã¼ã§ãã¼ãã£ã³ã°ã®ç¶æ
ãæ´æ°ãã¦ãã ãããä¾ãã° axiosã®ãã¼ã¿ãåãè¾¼ãå ´åã次ã®ãããªä¾ã«ãªãã¾ã:
data: function () {
return {
posts: [],
isLoading: false,
fetchError: null
}
},
watch: {
'$route': function () {
var self = this
self.isLoading = true
self.fetchData().then(function () {
self.isLoading = false
})
}
},
methods: {
fetchData: function () {
var self = this
return axios.get('/api/posts')
.then(function (response) {
self.posts = response.data.posts
})
.catch(function (error) {
self.fetchError = error
})
}
}
移è¡ã¬ã¤ã
ã³ã¼ãã«å¯¾ã 移è¡ãã«ãã¼ ãå®è¡ã $loadingRouteData
ã¡ã¿ããããã£ã使ç¨ããã¦ããç®æãæ¤åºãã¦ãã ããã