Vue.js router配置

首先我们的结构是这样的

main.js 中 主要加入这句话

import router from './router/router.js'

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router/router.js'
import elementui from 'element-ui'
import museui from 'muse-ui'
import mintui from 'mint-ui'
import store from './vuex/vuex-store.js'

import 'element-ui/lib/theme-chalk/index.css';
import 'muse-ui/dist/muse-ui.css';
import 'mint-ui/lib/style.css'

Vue.config.productionTip = false
Vue.use(elementui)
Vue.use(museui)
Vue.use(mintui)
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})

router.js 中是这么写

引入一个登录的LOGIN 一个主页的

import Vue from 'vue'
import Router from 'vue-router'
import LOGIN from '@/components/login'
import MAIN from '@/components/home'
import HOME  from './routers/home.js'
Vue.use(Router)

export default new Router({
  routes: [{
      path: '/',
      redirect: '/main'
    },
    {
      path: '/login',
      name: 'LOGIN',
      component: LOGIN,
    },
    {
      path: '/main',
      name: 'MAIN',
      component: MAIN,
      children:[
        HOME,
      ]
    }
  ]
})

home.js中

import home from '../../components/modules/home/index.vue'
export default {
	path: '/home',
	name: 'home',
	redirect: '/home/home_list',
	component: home,
	children: [{
		path: '/home/home_list',
		name: 'home_list',
		component:resolve => require(['@/components/modules/home/modules/list.vue'], resolve),
		meta:{name:'首页',parent:''}
	},
	]
}

在login.vue中 点击登录的时候跳转到home.vue

<template>
  <div class="hello">
    <div>
      <el-form  label-width="80px" :model="form">
        <el-form-item label="用户名">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password" type="password"></el-input>
        </el-form-item>
      </el-form>
       <mu-button color="primary" @click="jumphome">登录</mu-button>
       <mt-button size="normal" @click="dain">取消</mt-button>
    </div>
  </div>
</template>

<script>
export default {
  name: "HelloWorld",
  data() {
    return {
      form:{
        name:"",
        password:"",
      }
    };
  },
  watch:{

  },
  computed:{

  },
  methods:{
    jumphome(){
      this.$router.push({
        path: '/home/home_list',
        query: {
        },
      })
    },
    dain(){
      let param={
        username:this.form.name,
        password:this.form.password,
      }
      this.$store.dispatch("login/loginTest",param).then(res=>{

      })

    },

  },
  mounted(){

  },
  created(){

  },
};
</script>

<style scoped>
</style>

 home.vue

<template>
  <div class="hello">
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: "HelloWorld",
  data() {
    return {
      form:{
        name:"",
        password:"",
      }
    };
  },
  watch:{

  },
  computed:{

  },
  methods:{
  },
  mounted(){

  },
  created(){

  },
};
</script>

<style scoped>
</style>

这样就配置好了

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

侧耳倾听...

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值