我正在使用基于vue.js的nuxt.js开发一个网站。该网站是一个简单的网站,其中包含许多页面。我想创建一个知道其内容在哪里的组件,因此需要访问路由器对象。我已经尝试过$nuxt.$route.path
但出现错误。如何导入$nuxt
或$router
对象以在组件中访问它们?
我的模板组件
<template>
<div>
<hr>
<p>{{ $store.state.menuitems[0] }}</p>
<hr>
<div class="artfooter">
<span>i want name of current route here</span>
</div>
<br>
</div>
</template>
<style scoped>
.artfooter{
font-size: 0.8em;
display: flex;
justify-content: space-between;
}
</style>
<script>
import store from '~/store/index'
//how to import $nuxt object to access router??
console.log(store)
console.log(this.$router.path)
// the above console.log reports error
// Cannot read property 'middleware' of undefined
export default {
}
</script>
您可以通过this
以下方式访问它:
this.$route.path
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句