源码 j源码 j-step-c7

首先安装依赖

  • bash
yarn add vue-router -D

renderer目录下添加几个文件夹及文件,完成后项目结构差不多如下:

renderer
│
└───router
│   │   router-config.js
│   │   routes.js
│ 
└───views
│   │   Chat.vue
│   │   Login.vue
│ 
│   App.vue
│   index.js
  • views/Chat.vue

<template>
  <div>Chat</div>
</template>
  • views/Login.vue

<template>
  <div>Chat</div>
</template>
  • router/routes.js

import Login from '@/views/Login.vue'
import Chat from '@/views/Chat.vue'

export default [
  {
    path: '/',
    name: 'login',
    component: Login
  },
  {
    path: '/chat',
    name: 'chat',
    component: Chat
  }
]
  • routers/router-config.js

import routes from './routes.js'

export default { routes }
  • renderer/App.vue

<template>
  <div id="app">
    <router-view />
  </div>
</template>
  • renderer/index.js

import Vue from 'vue'
import Router from 'vue-router'
import routerConfig from './router/router-config.js'
import App from './App.vue'

Vue.use(Router)

const router = new Router(routerConfig)

// 关闭生产模式下给出的提示
Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
  • bash
yarn dev

ps: 在 开发者工具的Console 中 输入 location.hash = '#/chat' 可以切换路由

Logo

前往低代码交流专区

更多推荐