vue 跳转html页面,vue项目实现页面的跳转

第一步、最大的index.html页面 添加如下代码

目的

http://localhost:8080/(等同于http://localhost:8080/index.html)是父页面

其他的页面都是http://localhost:8080/路径名;也是子页面

主要是构建 SPA (单页应用) 时,方便渲染你指定路由对应的组件。你可以 router-view 当做是一个容器,它渲染的组件是你使用 vue-router 指定的。

cee607ff492ad1f5d883a60ba86384f5.png

第二步、main.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 hd from './App'

import ElementUI from 'element-ui'

import 'element-ui/lib/theme-chalk/index.css'

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

Vue.config.productionTip = false

Vue.use(ElementUI)

new Vue({

router,

el: '#app',

render:h => h(hd)

})

第三步、App.vue文件

第四步、router.js(本来是index.js,我改了名称)

我的目录结构如下

c2ad974c635401213e65f8055143f6e4.png

router.js代码如下

import Vue from 'vue'

import Router from 'vue-router'

import Head from '../components/head/Head'

import hmd from '../components/head/Zmd'

import ht from '../components/head/first'

import first from '../components/common/first'

import homd from '../components/home/Zmd'

Vue.use(Router)

export default new Router({

mode: 'history',

routes: [

{

path: '/head',

name: 'Head',

component: Head

},

{

path: '/first',

name: 'first',

component: first

},

{

path: '/hmd',

name: 'hmd',

component: hmd

}, {

path: '/homd',

name: 'homd',

component: homd

}, {

path: '/ht',

name: 'ht',

component: ht

}

, {

path: '/',

name: 'Head',

component: Head

}

]

})

第五步、实现路由跳转

由于我定义http://localhost:8080/就是head文件夹里面的Head.vue里面的内容

所以都是在这个Head.vue里面测试的

6937f9a0b6b953473921a94d80d8e8f2.png

components/head/Head.vue里面的内容如下

d5448a0cf077ad34a00c1109cb38602e.png

测试效果如下

1a7bc8c96d86ee25fd681e0dbc1a6e06.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值