老师,你的这个 vue-router 是 旧版本的,请问2.0版本的代码怎么实现?

来源:

捞拉

2016-11-19

老师,你的这个 vue-router 是 旧版本的,请问2.0版本的代码怎么实现?

写回答

7回答

ustbhuangyi

2016-11-19

目前课程是基于 Vue 1.0 版本的,所以 Vue-router 也是 0.7 版本。如果使用 Vue 2.0 开发,可以使用 Vue-router 2.0,和 1.0 的差别并不会太大~具体建议参考官网文档~

0
4
xlelou
回复
老孩er
看vue-router的版本 还有用的vue的版本吧 教程里用的vue1 和vue-router 0.7 ,我这边自动安装的是vue2 用的 vue-router2.0
2016-11-29
共4条回复

Simon_ITer

2017-01-25

我用vue2.0写了一个饿了么点餐系统的Demo,关于vue的一些基本用法都有用到,并且引入了vuex、vue-router、axios、webpack、eslint、better-scroll等,感兴趣可以来看看

https://github.com/SimonZhangITer/VueDemo_Sell_Eleme


2
0

潇11

2016-12-04

2.0 Vue-router的实现代码

import Vue from 'vue';
import App from './App';
import VueRouter from 'vue-router';
import VueResource from 'vue-resource';
import goods from 'components/goods/goods.vue';
import ratings from 'components/ratings/ratings.vue';
import seller from 'components/seller/seller.vue';

Vue.use(VueRouter);
Vue.use(VueResource);

const routes = [
  { path: '/goods', component: goods },
  { path: '/ratings', component: ratings },
  { path: '/seller', component: seller }
];

const router = new VueRouter({
  linkActiveClass: 'active',
  routes
})

/* eslint-disable no-new */
new Vue({
  template: '<App/>',
  components: { App },
  router: router
}).$mount('#app');

router.push('/goods');


2
1
林与初
router.push('/goods');可以取消了,在routes 里增加一个{ path: '/', redirect: { path: '/goods' } }~否则在ratings会报错
2017-01-04
共1条回复

野蛮生长的草

2017-03-03

老师,安装好stylus-loader后提示 ERROR in Cannot find module 'stylus'     根据提示似乎是stylus这个模块无法找到,于是我又全局npm install -g stylus   之后重新运行代码还是报上面的错误。请问是什么原因?????

0
0

雪碧爹

2017-02-09

老师,什么时候会更新为2.0啊

0
0

ai7hoo

2016-12-04

我也是直接使用的2.0的版本,这是我得实现。https://github.com/ai7hoo/sell/blob/master/src/main.js

0
0

无人no1

2016-12-02

我vue用的是2.0   vue-router 也是用的2.0 的        api有点差别  这是我的代码: https://github.com/johnnyWu1/vue_sell_app (57%)

0
1
宋婷
安装你的代码进行了更改,但是我这里提示组件component没定义,不清楚应该是什么原因,您遇到过吗 vue-router.js?e71f:1800Uncaught TypeError: Cannot read property 'component' of undefined vue.common.js?e881:5846Download the Vue Devtools for a better development experience: https://github.com/vuejs/vue-devtools
2016-12-05
共1条回复

Vue.js2.5+cube-ui重构饿了么App(经典再升级)

掌握Vue1.0到2.0再到2.5最全版本应用与迭代,打造极致流畅的WebApp

9868 学习 · 4162 问题

查看课程