【发布时间】:2019-12-23 12:55:39
【问题描述】:
我的第一个 Vue 项目,我想在每个路由器调用上运行加载效果。
我做了一个Loading 组件:
<template>
<b-loading :is-full-page="isFullPage" :active.sync="isLoading" :can-cancel="true"></b-loading>
</template>
<script>
export default {
data() {
return {
isLoading: false,
isFullPage: true
}
},
methods: {
openLoading() {
this.isLoading = true
setTimeout(() => {
this.isLoading = false
}, 10 * 1000)
}
}
}
</script>
我想像这样放置在路由器内部:
router.beforeEach((to, from, next) => {
if (to.name) {
Loading.openLoading()
}
next()
}
但是我收到了这个错误:
TypeError:“_components_includes_Loading__WEBPACK_IMPORTED_MODULE_9__.default.openLoading 不是函数”
我该怎么办?
【问题讨论】:
标签: vue.js vue-component vue-router