Vue--路由
main.js:
1、先在项目安装路由模块:npm install vue-router --save-dev
2、使用路由:main.js首先要引用vue模块:
import Vue from 'vue'
3、再引用路由模块:
import VueRouter from ‘vue-router’
4、使用VueRouter:
Vue.use(VueRouter)
5、配置路由:
import Home from './components/home' /父级组件
import HelloWorld from './components/HelloWorld' /子组件 const router = new VueRouter({
routes:[
{path:‘/’,component:Home}//主页地址
{path:‘/helloworld’,component:HelloWorld}//地址
],
mode:‘history’ //添加这个属性后页面地址就不存在#/的问题
})
6、引用配置好的路由router:
new Vue({
router,
el:'#app'
components: { App },//这是根组件
templater:'<App/>'
})
根目录:这里是App.vue
7、找到路径后,在根组件展示:
<router-view></router-view>
此时刷新界面页面地址变成http://localhost:8080/#/,
当在地址输入http://localhost:8080/#/helloworld,就会跳转到helloworld这个界面
7、写到这里就可以使用a标签跳转了
但是会刷新界面
根目录:App.vue
<templater>
<div id='app'>
<router-view></router-view>
<ul>
<li><a href='/'>home</a></li> //href的地址必须是配置路由的地址
<li><a href='/helloworld'>hello</a></li> //href的地址必须是配置路由的地址
</ul>
</div>
</templater>
8、路由跳转:
不会刷新界面,高效率!
<templater>
<div id='app'>
<router-view></router-view>
<ul>
<li><router-link to='/'>home</router-link></li> //href的地址必须是配置路由的地址
<li><router-link to='/helloworld'>hello</router-link></li> //href的地址必须是配置路由的地址
</ul>
</div>
</templater>
Vue--路由的更多相关文章
- Vue路由vue-router
前面的话 在Web开发中,路由是指根据URL分配到对应的处理程序.对于大多数单页面应用,都推荐使用官方支持的vue-router.Vue-router通过管理URL,实现URL和组件的对应,以及通过U ...
- 攻克vue路由
先下手 路由是个好功能,但是每次都感觉没法开始下手,愣愣的看半天官方文档,所以做个快速开始教程. 首先先搭好HTML文件结构: <!--link和view在一个父元素下--> <di ...
- Vue路由学习心得
GoodBoy and GoodGirl~进来了就看完点个赞再离开,写了这么多也不容易的~ 一.介绍 1.概念:路由其实就是指向的意思,当我们点击home按钮时,页面中就要显示home的内容,点击l ...
- VUE路由新页面打开的方法总结
平常做单页面的场景比较多,所以大部分的业务是在同一个页面进行跳转.要通过VUE路由使用新页面打开且传递参数,可以采用以下两个方法: 1.router-link的target <router-li ...
- vue路由参数变化刷新数据
当路由到某个组件时,由于组件会复用,所以生命周期函数不会再次执行, 如果这个组件是模板组件,靠传入不同数据来显示的.那么,可能会发生参数变化了但页面数据却不变化. 问题 假如有个组件 info.vue ...
- 10.3 Vue 路由系统
Vue 路由系统 简单示例 main.js import Vue from 'vue' import App from './App.vue' //https://router.vuejs.or ...
- vue路由原理剖析
单页面应用(SPA)的核心之一是: 更新视图而不重新请求页面, 实现这一点主要是两种方式: 1.Hash: 通过改变hash值 2.History: 利用history对象新特性(详情可出门左拐见: ...
- 3种vue路由传参的基本模式
路由是连接各个页面的桥梁,而参数在其中扮演者异常重要的角色,在一定意义上,决定着两座桥梁是否能够连接成功. 在vue路由中,支持3中传参方式. 场景,点击父组件的li元素跳转到子组件中,并携带参数,便 ...
- 14.vue路由&脚手架
一.vue路由:https://router.vuejs.org/zh/ 1.定义 let router = new VueRouter({ mode:"history/hash" ...
- react router @4 和 vue路由 详解(八)vue路由守卫
完整版:https://www.cnblogs.com/yangyangxxb/p/10066650.html 13.vue路由守卫 a.beforeEach 全局守卫 (每个路由调用前都会触发,根据 ...
随机推荐
- jQuery EasyUI 折叠面板accordion的使用实例
1.对折叠面板区域 div 设置 class=”easyui-accordion” 2.在区域添加多个 div, 每个 div 就是一个面板 (每个面板一定要设置 title 属性). 3.设置面板属 ...
- vue中的适配:px2rem
这应该是vue项目在适配移动端时候,最简单的方法之一下面是基本步骤(使用cnpm)1.下载并引入lib-flexible cnpm install --save lib-flexible 在main. ...
- 索引使用,分析初探。(explain分析执行计划,以及强制使用force index)
促使这次探索的初衷还是因为要对一个定时脚本性能进行优化. 脚本有两个指定状态分别是status, latest_process_status,和一个超期时间expire_time进行限制. 按照我以前 ...
- spring 标签
*/ @Slf4j @Service public class RetryService { @Autowired private MqConfig mqConfig; /** * 如果网络连接失败, ...
- placeholder解决兼容各种IE浏览器的方法
<input id="search" type="text" class="box" class="inputText&qu ...
- 莫烦theano学习自修第二天【激励函数】
1. 代码如下: #!/usr/bin/env python #! _*_ coding:UTF-8 _*_ import numpy as np import theano.tensor as T ...
- 老男孩python学习自修【第二天】字符串用法
实时处理增量日志最佳实践 主要使用f.seek()和f.tell()实现 字符串处理函数: s.find(substr, start, end) 查找子字符串,找不到则返回-1,找到则返回对应的索引 ...
- python工具使用笔记
1.pip pip是Python官方推荐的包管理工具,在doc界面直接使用pip或者pip3命令即可,例如安装gensim: C:\Users\kayan.sjc>pip3 install -- ...
- commons-lang
今天在编码的过程中,对于null,采用==null进行判断.并且为了过滤"",使用了str.trim().length()==0,当str为null时,报空指针异常. 于是决定使用 ...
- layui tips