Skip to content

[vue] 如果让你从零开始写一个vue路由,说说你的思路 #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
haizhilin2013 opened this issue Jun 20, 2019 · 3 comments
Open
Labels
vue vue

Comments

@haizhilin2013
Copy link
Collaborator

[vue] 如果让你从零开始写一个vue路由,说说你的思路

@haizhilin2013 haizhilin2013 added the vue vue label Jun 20, 2019
@xjt31012
Copy link

创建完页面后,在router.js里创建一个路径,(一般刚创建项目时会有Home和About的示例,我都是直接复制一下他们的路由然后再改成自己的),然后在对应的页面中引用

@slmyer
Copy link

slmyer commented Jun 27, 2019

就是暴露install 和 router 然后初始化 还有注册link view 组件 监听hash变化 切换当前组件 然后render实现不同组件的渲染 这只是hash模式

@zlqGitHub
Copy link

  1. 为了方便后期维护,建议独立出一个 router.js 文件
  2. npm install vue-router
  3. 引入注册
import Router from 'vue-router';
Vue.user(Router);
  1. 向外暴露出一个router实例
export default new Router({
    mode: '',
    path: '',
    name: '',
    ...
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vue vue
Projects
None yet
Development

No branches or pull requests

4 participants