vue2.0路由
现在用vue-cli搭建的环境里面vue-router是下载好的
vue2.0路由方式和以前也有些不同
没了了map和start方法
目录结构如上图
这里有三个文件,app.vue显示,main.js控制路由,goods.vue为跳转页面
app.vue
template>
<div id="app">
<v-header></v-header>
<div class="tab">
<div class="tab-item">
<router-link to="/goods">商品</router-link>
</div>
<div class="tab-item">评论</div>
<div class="tab-item">商家</div>
</div>
<router-view></router-view>
</div>
</template> <script>
import header from './components/header/header.vue'; export default{
components:{
'v-header':header
}
};
</script> <style lang="stylus" rel="stylesheet/stylus">
#app
.tab
display:flex
width:100%
height:40px
line-height:40px
.tab-item
flex:1
text-align center </style>
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 VueRouter from 'vue-router'
import App from './App'
import goods from './components/goods/goods.vue';
import ratings from './components/ratings/ratings.vue';
import seller from './components/seller/seller.vue'; import "./common/stylus/index.styl";
Vue.use(VueRouter);
Vue.config.productionTip = false; const routers=[
{path:'/goods',component:goods},
{path:'/ratings',component:ratings},
{path:'/seller',component:seller}
]
const router=new VueRouter({
linkActiveClass:"active",
mode:"history",
routes:routers
}); const app = new Vue({
router
}).$mount('#app') new Vue({
template: '<App/>',
components: { App },
router: router
}).$mount('#app'); router.push('/goods')
// 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 VueRouter from 'vue-router'
import App from './App'
import goods from './components/goods/goods.vue';
import ratings from './components/ratings/ratings.vue';
import seller from './components/seller/seller.vue'; import "./common/stylus/index.styl";
Vue.use(VueRouter);
Vue.config.productionTip = false; const routers=[
{path:'/goods',component:goods},
{path:'/ratings',component:ratings},
{path:'/seller',component:seller}
]
const router=new VueRouter({
linkActiveClass:"active",
mode:"history",
routes:routers
}); const app = new Vue({
router
}).$mount('#app') new Vue({
template: '<App/>',
components: { App },
router: router
}).$mount('#app'); router.push('/goods')
vue2.0路由的更多相关文章
- vue2.0路由写法、传参和嵌套
前置知识请戳这里 vue-routerCDN地址:https://unpkg.com/vue-router@3.0.1/dist/vue-router.js vue-router下载地址:https: ...
- vue2.0路由变化1
路由的步骤 1.定义组件 var Home={ template:'<h3>我是主页</h3>' }; var News={ template:'<h3>我是新闻& ...
- vue2.0路由进阶
一.路由的模式 第一种用history方式实现,HTML5使用window.history.pushState()实现路由的切换而不刷新页面. 第二种使用hash值的方式来实现. vue2.0两种都可 ...
- vue2.0路由-路由嵌套
vue一个重要的方面就是路由,下面是自己写的一个路由的例子: 1.引入依赖库就不必再说 2.创建组件 两种写法 第一种:间接 <template id="home"> ...
- vue2.0 路由学习笔记
昨天温故了一下vue2.0的路由 做个笔记简单记录一下! 1.首相和vue1.0一样 要使用vuejs的路由功能需要先引入vue-router.js 2.然后修改原有a标签处代码 这里以一个ul li ...
- 解决vue2.0路由 TypeError: Cannot read property 'matched' of undefined 的错误问题
刚开始使用vue-router2.0,虽然也用了vux,用起来却发现一个问题--具体如下: 正常情况下使用脚手架跑完之后,然后修改源项目,首先在main.js入口里把该import进去的vuex,vu ...
- vue2.0路由切换后页面滚动位置不变BUG
最近项目中遇到这样一个问题,vue切换路由,页面到顶端的滚动距离仍会保持不变. 方法一: 监听路由 // app.vue export default { watch:{ '$route':func ...
- vue2.0路由写法
// 0. 如果使用模块化机制编程,導入Vue和VueRouter,要调用 Vue.use(VueRouter) // 1. 定义(路由)组件. // 可以从其他文件 import 进来 var Fo ...
- vue2.0 路由传参(router-link传过去)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
随机推荐
- 02-MySQL的安装和配置
1. 软件和环境 注:安装MySQL数据库的操作系统必须保证有.NET环境和VC运行库的支持. 下载地址:百度云网盘链接 2. MySQL服务器安装详细步骤 (1). 选择安装类型 这里我们选择 ...
- Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
使用JProfiler监控JAVA程序内存,JVM报错: A fatal error has been detected by the Java Runtime Environment: EXCEPT ...
- 百度编辑器 Ueditor 如何增加模板 ?
模板文件在这里: dialogs/template/config.js 参见:http://t.mreald.com/191 .
- buildroot构建项目(七)--- u-boot 2017.11 适配开发板修改 4 ---- 系统启动初始化之四
设置完寄存器控制器后,则跳出cpu_init_crit,进入_main 函数.即进入crt0.S (arch\arm\lib) 跟着代码流程慢慢走 一.crt0.S 1.1 第一步执行代码 /* 预 ...
- python - class propert应用
propert应用 #方式一: # class Student(object): # def __init__(self,name,sc): # self.name = name # self.sc ...
- Informatic学习总结_day02_增量抽取
SELECT EMP.EMPNO, EMP.ENAME, EMP.JOB, EMP.MGR, EMP.HIREDATE, EMP.SAL, EMP.COMM, EMP.DEPTNO FROM EMP ...
- SpringBoot整合MyBatis(注解版)
详情可以参考Mybatis官方文档 http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/ (1). ...
- Python|绝不乱入的靠谱书单
- React-Native 之 项目实战(一)
前言 本文有配套视频,可以酌情观看. 文中内容因各人理解不同,可能会有所偏差,欢迎朋友们联系我. 文中所有内容仅供学习交流之用,不可用于商业用途,如因此引起的相关法律法规责任,与我无关. 如文中内容对 ...
- JavaScript的类型自动转换高级玩法JSFuck
0 前言 最开始是不小心在微信公众号(程序员大咖)看到一篇JS的高逼格代码,然后通过里面的链接跳转到了JSFuck的wiki,就像顺着迷宫找宝藏的感觉,感叹JS的自动类型转换的牛逼. 1 样例 (!( ...