VUE 使用路由跳转登录页面

新建终端,配置下载:

npm install 

npm install vue-router

在src/components路径下新建首页 Shouye.vue:

<template>

    <div>

        <router-view></router-view>

    </div>

</template>

<script>

    export default {

       

    }

</script>

<style lang="scss" scoped>

</style>

在src/components路径下新建登录页面 Login.vue

<template>

    <div>

        用户名:<input type="text" v-model="username">

        密码:<input type="text" v-model="password">

        <button @click="login">登录</button>

    </div>

</template>

<script>

    export default {

        data() {

            return {

                username:'',

                password:''

            }

        },

        methods:{

            login(){

                this.$router.push('/menu')

            }

        }

    }

</script>

<style lang="scss" scoped>

</style>

打开main.js,添加router路由配置信息:

import { createApp } from 'vue'

// import './style.css'

import App from './components/Shouye.vue'

import router from './router.js'

const app=createApp(App)

app.use(router)

app.mount('#app')

在src/components路径下新建登录成功进入的页面Menu.vue:

<template>

    <div>

        登录成功

    </div>

</template>

<script>

    export default {

    }

</script>

<style lang="scss" scoped>

</style>

在src路径下,新建router.js,配置路由:

import { createRouter, createWebHistory } from "vue-router";

import login from './components/Login.vue'

import menu from './components/Menu.vue'

const router=createRouter({

    history:createWebHistory(),

    routes:[

        {path:'/login',component:login},

        // 默认登录页面Login

        {path:'/',redirect:'/login'},

        {path:'/menu',component:menu}

    ]

})

export default router

新建终端,输入npm run dev 查看运行效果:

  • 28
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值