Vue前端页面跳转,登录成功跳转页面

在以往不用框架的时候,我通常是通过href,或者重定向进行跳转。

对于vue,他有专门的router路由进行跳转。

所以第一步,我们要像python一样,在npm中安装并且在项目中引用他

思路:

用户点击登录后,跳转到Index.vue界面

我的默认页面是SignIn.vue,是登录页面

SignIn.vue

 Index.vue

我刚刚干了什么(可以跳过)?

这个页面我还没有画,我先画个原型图(等我2分钟)

代码写完了,我觉得下面没有必要,到多少页,业务不需要,所以删了,

另外内容封面,名字在上面太丑,放到下面了。这是画完的网站图

附送界面代码

框架我用的vue+bootstrap

先看我的main.js

import Vue from 'vue'


import VueCookies from 'vue-cookies'
import Index from './Index.vue'

import "./bootstrap-3.4.1-dist/css/bootstrap.css"



Vue.use(VueCookies)



new Vue({
  render: h => h(Index),
}).$mount('#app')

Index.vue


<template>
	
	<div id="app" style="margin-left: 5%;margin-right: 5%;border: 3px solid red;">
		
		<!-- 标题 -->
		<div id="top_welcome" style="width: 100%px;height: 60px;border: 2px solid blue;"><h3>欢迎尾号为1268的大神</h3></div>
		
		<!-- 过滤搜索栏 -->
		<div id="top_filter" style="width: 100%px;height: 40px;border: 2px solid green;">
			<div id="top_filter_button" style="width: 30%px;height: 40px;
			border: 1px solid purple;float: left;;">
			<input style="margin-right: 10px;" type="button" class="btn btn-primary" value="全部作品">
			<input style="margin-right: 10px;" type="button" class="btn btn-success" value="我的作品">
			</div>
			<div id="top_filter_search" class="input-group col-md-3" style="margin:1px; positon:relative" >
				<input type="text" class="form-control"placeholder="请输入搜索内容(作品名 或 作者)"/>
				<span class="input-group-btn">
			    <button class="btn btn-info btn-search" style="background-color: purple;">搜索</button>
				</span>							   
			</div>
		</div>
		<!-- 主体 -->
		<div id="content" style="width: 100%px;height: 500px;margin-top: 5px;border: 5px solid green;">
			
			<div id="content_project" style="width: 100%px;height: 350px;margin: 10px;border: 2px solid purple;float: left;">

			<div style="width: 120px;height: 150px;margin: 10px;border: 2px solid red;float: left;">
					<img alt="Vue logo" style="width: 60;height: 100px;" src="./assets/logo.png">
					<div  style="width: 20;height: 45px;border: 2px solid blue;">
						<b>贪玩蓝月</b>
						<p>渣渣辉</p>
					</div>
			</div>

			<div style="width: 120px;height: 150px;margin: 10px;border: 2px solid red;float: left;">
					<img alt="Vue logo" style="width: 60;height: 100px;" src="./assets/logo.png">
					<div  style="width: 20;height: 45px;border: 2px solid blue;">
						<b>篮球小王子教学</b>
						<p>蔡徐坤</p>
					</div>
			</div>
			
			<div style="width: 120px;height: 150px;margin: 10px;border: 2px solid red;float: left;">
					
			</div>
			<div style="width: 120px;height: 150px;margin: 10px;border: 2px solid red;float: left;">
					
			</div>
			

			</div>

			

			<div id="content_page_limit" style="width: 100%;height: 60px;border: 2px solid green;float: left;">
					<ul class="pagination">
					    <li><a href="#">&laquo;</a></li>
					    <li class="active"><a href="#">1</a></li>
					    <li class="disabled"><a href="#">2</a></li>
					    <li><a href="#">3</a></li>
					    <li><a href="#">4</a></li>
					    <li><a href="#">5</a></li>
					    <li><a href="#">&raquo;</a></li>
					</ul>
			</div>
		</div>

	</div>
</template>

<script>
	export default {
	  name: 'app',
	  components: {

	  },data(){
	  		return {
				
			}}
      ,methods:{
		  
	  }					
	}
</script>

<style>

</style>

跳转router

下载安装router,npm

npm install vue-router

创建router目录和index.js文件

 

router配置下的index.js配置

index.js

这下面的componet:()=>import指向的是,我上面那个(欢迎尾号xxx的大神)这个vue页面

import Vue from 'vue'
import VueRouter from 'vue-router'

//调用 Vue.use()函数,把VueRouter 安装为Vue的插件
Vue.use(VueRouter);


//向外共享路由的实例对象
export default new VueRouter({
	//这个就是路由项目配置,如果有多个,请用,隔开。用{}加上多个跳转地址
	routes:[
		{
		path: 'index1', 
		name: 'index1',
		component: ()=>import('../../src/Index.vue')
		}
		]
})

我这写了一个页面。主要的跳转代码

 router-view(是必须存在,否则跳转后将不显示)

router-link 是跳转标签

测试

 

  • 2
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
回答: 为了解决Vue3路由跳转页面不跳的问题,可以尝试以下解决方案。首先,在大页面(Layout组件)的路由容器上加一个key属性,可以使用路由路径加上一个随机数作为key值。例如:`<router-view :key="key"></router-view>`,并在computed属性中定义key方法,返回`this.$route.path + Math.random()`。这样可以确保每次路由跳转时都会重新渲染页面。\[1\] 另外,可以在App组件中添加一个路由出口,将其作为跳转页面的目标。可以在App组件中使用render函数,返回一个`<router-view>`组件。这样在点击时会跳转到这个出口页面,展示注册页面。\[2\] 最后,如果是在三级路由中出现页面不跳转的问题,可以在三级路由的根元素中添加样式,例如设置一个绝对定位的div元素,并设置宽度、高度和背景颜色等样式。这样可以确保页面内容正常显示。例如:`<div style="position:absolute;background: white; width:calc(86%);height: calc(96%);z-index: 999;">我是商品详情</div>`。\[3\] 通过以上解决方案,可以解决Vue3路由跳转页面不跳的问题。 #### 引用[.reference_title] - *1* *3* [Vue 面包屑三级路径改变但页面不跳转解决方案](https://blog.csdn.net/m0_46183499/article/details/128313204)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [vue2路由跳转,页面不跳的问题](https://blog.csdn.net/Daisy_ls/article/details/125814769)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值