vueJs+webpack单页面应用--vue-router配置
vue-route版本要跟vue版本同步,我的vue用的2.0+的,vue-router 也用了最新版2.1+
npm安装vue-router:
$ npm install vue-router --save-dev
使用:
1.引入 vue-router: import VueRouter from 'vue-router';
2.注册: Vue.use(VueRouter);
3.配置路径:
const routes = [
{ path: '/goods', component: goods },
{ path: '/seller', component: seller },
{ path: '/ratings', component: ratings }
];
const router = new VueRouter({
linkActiveClass: 'active',
routes: routes
});
4.初始化Vue(备注:
直接new Vue不赋值 需上面加上 /* eslint-disable no-new */注释
):
/* eslint-disable no-new */
new Vue({
router: router,
...App
}).$mount('#app');
5.push进来第一个路径
router.push('/goods');
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 App from './App';
import VueRouter from 'vue-router';
import goods from './components/goods/goods';
import seller from './components/seller/seller';
import ratings from './components/ratings/ratings'; Vue.use(VueRouter); const routes = [
{ path: '/goods', component: goods },
{ path: '/seller', component: seller },
{ path: '/ratings', component: ratings }
]; const router = new VueRouter({
linkActiveClass: 'active',
routes: routes
}); /* eslint-disable no-new */
new Vue({
router: router,
...App
}).$mount('#app'); router.push('/goods');
1. 定义路由链接: <router-link to="/goods">商品</router-link>
2. 路由匹配到的组件将渲染在这里 <router-view></router-view>
App.vue 源码:
<template>
<div>
<v-header></v-header>
<div class="tab">
<div class="tab-item">
<router-link to="/goods">商品</router-link>
</div>
<div class="tab-item">
<router-link to="/ratings">评论</router-link>
</div>
<div class="tab-item">
<router-link to="/seller">商家</router-link>
</div>
</div>
<!-- 路由匹配到的组件将渲染在这里 -->
<router-view></router-view>
</div>
</template> <script>
import header from './components/header/header';
export default {
components: {
'v-header': header
}
};
</script> <style lang="stylus" rel="stylesheet/stylus">
.tab
font-size: 28px
display: flex
.tab-item
height: 40px
line-height: 40px
text-align: center
flex: 1
</style>
vueJs+webpack单页面应用--vue-router配置的更多相关文章
- Kendo UI 单页面应用(二) Router 类
Kendo UI 单页面应用(二) Router 类 Route 类负责跟踪应用的当前状态和支持在应用的不同状态之间切换.Route 通过 Url 的片段功能(#url)和流量器的浏览历史功能融合在一 ...
- 深入浅出的webpack构建工具--webpack4+vue+router项目架构(十四)
阅读目录 一:vue-router是什么? 二:vue-router的实现原理 三:vue-router使用及代码配置 四:理解vue设置路由导航的两种方法. 五:理解动态路由和命名视图 六:理解嵌套 ...
- webpack 单页面应用实战
这篇文章将介绍如何利用 webpack 进行单页面应用的开发,算是我在实际开发中的一些心得和体会,在这里给大家做一个分享.webpack 的介绍这里就不多说了,可以直接去官网查看. 关于这个单页面应用 ...
- Oracle JET 单页面应用程序Router 使用(上)
单页面应用程序:使用一个进加载一次的网页,如果页面由于用户的交互而改变,则仅绘制更改的页面部分. 要创建单页面应用程序需要使用 oj.Router 的虚拟导航来支持,ojModule 用来响应页面的重 ...
- 友盟统计单页面应用vue
根据友盟官方提示在index.html的body标签末尾加入相关代码后: 后来发现,由于项目为单页面应用,在路由发生跳转时(到其他页面了),并不会重新将新页面加入统计中.需要在App.vue页面中,监 ...
- vue router 配置默认页/404页面
*号通配404默认页面
- Kendo UI开发教程(24): 单页面应用(二) Router 类
Route类负责跟踪应用的当前状态和支持在应用的不同状态之间切换.Route通过Url的片段功能(#url)和流量器的浏览历史功能融合在一起.从而可以支持把应用的某个状态作为书签添加到浏览器中.Rou ...
- IIS部署的H5的单页面跳转的配置
<?xml version="1.0" encoding="UTF-8"?><configuration> <system.web ...
- vue 单页面(SPA) history模式调用微信jssdk 跳转后偶尔 "invalid signature"错误解决方案
项目背景 vue-cli生成的单页面项目,router使用history模式.产品会在公众号内使用,需要添加微信JSSDK,做分享相关配置. 遇到的问题 相关配置与JS接口安全域名都已经ok,发布后, ...
随机推荐
- 【Demo】QQ,github,微博第三方社交登录
本文主要讲解 集成 第三方社交账号登录 为什么会有这个需求? 主要是因为目前互联网的网站数量太多,如果在各个站点都注册一个账号 用户非常不容易记住每个账号的用户名和密码,并且非常难保证每个账号的密码足 ...
- objective-c static变量的使用总结
在java中,我们经常使用的是单例模式,这些设计模式在ios开发中也比较常用,最近也在考虑使用在ios开发中使用单例模式 在objective-c中,需要在.m文件里面定义个static变量来表示全局 ...
- 基于FormsAuthentication的用户、角色身份认证
一般情况下,在我们做访问权限管理的时候,会把用户的正确登录后的基本信息保存在Session中,以后用户每次请求页面或接口数据的时候,拿到 Session中存储的用户基本信息,查看比较他有没有登录和能否 ...
- [原]简易android反编译教程
1.apktool d -f <.apk> <output> 反编译出资源文件(及smali)2.使用winrar打开apk,提取出classed.dex,执行 d2j-dex ...
- C#基础知识记录一
C#基础知识记录一 static void Main(string[] args) { #region 合并运算符的使用(合并运算符??) 更多运算符请参考:https://msdn.microsof ...
- Centos6 换源
#主要是为了提高安装速度以及epel中自带源众多木有的软件. #Author wood_man #2016.06.01 v 2.0 1. 测试环境 VMware 10.0 CentOS rele ...
- java实现excel表格导出数据
/** * 导出清单 eb中 firstRow(EntityBean) 列表第一行数据,键值对(不包含序号)例:("name","姓名") * data(Ent ...
- 化繁为简,最简易的SqlDataSource配合Cache使用~
最近一个小项目用了比较方便傻瓜的DevExpress控件,实践中DevExpress的控件确实很方便. 在用ASPxGridView控件的时候,为了偷懒结合了SqlDataSource使用,但一直在大 ...
- eclipse tomcat 集成
1. 下载 Tomcat 作者选择的是 Tomcat6,下载地址:http://tomcat.apache.org/download-60.cgi,选择绿色版的 zip 进行下载(目前最 ...
- 从js向Action传中文参数出现乱码问题的解决方法
Action获取jsp表单中的中文参数,只要整个项目都采用UTF-8编码格式都不会出现乱码问题:但JSP中用到JS,并从JS向Action传中文参数,就会出现中文乱的现象 做项目的时候,发现A ...