【发布时间】:2019-05-05 13:42:55
【问题描述】:
我正在使用 Vue CLI 3,它创建了一些路由。一个是 Home.vue。在我的程序中,我试图以编程方式转到不同的页面。我在 router.js 中添加了我需要的路由,但保留了已经为 Home.vue 和 About.vue 创建的路由。它工作正常,直到我到达“家”并收到警告:[vue-router] 名为“家”的路由不存在。'
代码如下:
<template>
<div class='secondItem'>
<h4 v-for="item in menuItems"
@click="bindMe(item)" v-bind:class="{'active':(item === current)}">{{item}}</h4>
</div>
</template>
<script>
export default {
name: 'Header',
data() {
return {
current: '',
menuItems: ['Home', 'About', 'Portfolio', 'Contact'],
}
},
methods: {
bindMe(item) {
this.current = item;
this.$router.push({
path: item
})
}
}
}
<script>
【问题讨论】:
标签: vue.js vue-router