您的位置:首页技术文章
文章详情页

javascript - vue的router-link报错不显示

浏览:61日期:2022-12-16 16:17:45

问题描述

我用vue-cli搭建好了目录,但是用router-link做单页路由没有成功,不知道哪里有问题求解,本人刚进坑

app.vue

<template> <p id='app'> <headers></headers> <p class='tap'><p class='tab-item'> <router-link :to='/Goods'>第一项</router-link></p><p class='tab-item'> <router-link to='/Ratings'>第二项</router-link></p><p class='tab-item'> <router-link to='/Seller'>第三项</router-link></p><router-view></router-view> </p> </p></template><script>import headers from ’./components/header/header’; export default { components:{headers }, name: ’app’,};</script>

main.js

import Vue from ’vue’import App from ’./App’import router from ’./router’Vue.config.productionTip = false/* eslint-disable no-new */new Vue({ el: ’#app’, router, template: ’<App/>’, components: { App }})

其中一个单页,其他都基本一致

<template lang='html'> <p id='ratings'><p class='heihei'> {{arr}}</p> </p></template><script> export default{name:’Ratings’,data: { arr:’afafaf’} };</script>

index.js

import Vue from ’vue’import Router from ’vue-router’import Goods from ’@/components/goods/goods’import Ratings from ’@/components/ratings/ratings’import Seller from ’@/components/seller/seller’Vue.use(Router)export default new Router({ routes: [ { path: ’/Goods’, component: Goods },{ path: ’/Ratings’, component: Ratings },{ path: ’/Seller’, component: Seller }, ]})

问题解答

回答1:

<template> <p id='app'> <headers></headers> <p class='tap'><p class='tab-item'> <router-link :to='/Goods'>第一项</router-link></p><p class='tab-item'> <router-link to='/Ratings'>第二项</router-link></p><p class='tab-item'> <router-link to='/Seller'>第三项</router-link></p><router-view></router-view> </p> </p></template>

要么都写成 to=’someRoute’ 要么都写成 :to=’{path: 'someRoute'}’

回答2:

index.js 里面 加上

export default router

import Vue from ’vue’import Router from ’vue-router’import Goods from ’@/components/goods/goods’import Ratings from ’@/components/ratings/ratings’import Seller from ’@/components/seller/seller’Vue.use(Router)const router = new Router({ routes: [ { path: ’/Goods’, component: Goods },{ path: ’/Ratings’, component: Ratings },{ path: ’/Seller’, component: Seller }, ]})export default router

标签: JavaScript
相关文章: