vue 同一个页面路由无反应_一个vue路由的问题,路由改变,页面不变?

本文探讨了一个Vue应用中遇到的问题,即在同一个页面内的路由切换时,页面内容没有相应更新。尽管路由发生变化,但视图并未正确加载。通过检查路由配置和组件代码,发现可能是路由级别代码分割、组件状态或VueRouter的某些特性导致的问题。在深入分析和解决这个问题的过程中,可以更好地理解Vue Router的工作原理。
摘要由CSDN通过智能技术生成

怎么测都是好的,代码如下,大部分copy你得代码,路径可能有点不同

效果如图

47b4b707fe03cb4be729e4268098ffd6.gif// 路由配置

import Vue from 'vue'

import VueRouter, { RouteConfig } from 'vue-router'

import Main from '../views/Main.vue'

Vue.use(VueRouter)

const routes: Array = [

{

path: '/login',

name: 'Login',

component: () => import('../views/Account/Login.vue')

},

{

path: '/',

name: 'Main',

component: Main,

redirect: 'home',

children: [

{

path: '/home',

name: 'Home',

component: () => import('../views/Home.vue')

},

{

path: '/about',

name: 'About',

// route level code-splitting

// this generates a separate chunk (about.[hash].js) for this route

// which is lazy-loaded when the route is visited.

component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')

},

]

},

]

const router = new VueRouter({

mode: 'history',

routes

})

export default router// login页面

跳转到首页

import { Component, Vue } from "vue-property-decorator";

export default class Login extends Vue {}

// main页面

export default {

name: "Main"

}

// about页面

This is an about page

import {Component, Vue} from "vue-property-decorator";

@Component

export default class About extends Vue{

private created() {

console.log(this.$route)

}

}

// home页面

logo.png

import {Component, Vue} from "vue-property-decorator";

@Component

export default class Home extends Vue {

}

// app页面

import {Component, Vue, Watch} from "vue-property-decorator";

@Component

export default class App extends Vue {

// @Watch('key')

// public watchKey(newV: any) { // console.log(newV) // } // // get key() { // console.log(1) // return this.$route.fullPath // }

public mounted() {

console.log(this.$route)

}

}

#app {

font-family: Avenir, Helvetica, Arial, sans-serif;

-webkit-font-smoothing: antialiased;

-moz-osx-font-smoothing: grayscale;

text-align: center;

color: #2c3e50;

}

#nav {

padding: 30px;

a {

font-weight: bold;

color: #2c3e50;

&.router-link-exact-active {

color: #42b983;

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值