-
vue-router
- 根据url进行动态的don移除增加操作,就是路由器的作用
- 在router.js中加上 mode: 'history',可以优化引擎
http://localhost:8080/#/page1 == ( mode: 'history ') == http://localhost:8080/page1-
进行页面间的跳转
this.$router.push('/page2/vuejs') -
router使用
- 配置路由
- 安放路由出口
<router-view> - 导航链接
<router-link> - 传参方式
- 占位符传参(必选参)
- 查询参的参数(可选参)
$route,$query获取参数
- 嵌套
- 异步路由: 路由懒加载异步组件
- 守卫--处理权限的问题
router.beforeEach((to,from,next)=>{- 全局router.beforeEach
- 路由beforeEnter
- 组件beforeRouteEnter
-
命令: vue add router
-
$router进行跳转是路由器 ;$route获取参数是路由 -
带参数进行跳转时如: /page2/1/vue.js(含有两个参数)
this.$router.push({name: 'page2',params: {id: 1,msg: 'vue.js'}}) //router.js routers: [ {path: '/page2/:id/:msg',name: 'page2',component: Page2} {path: '/static',component: Page1,props: {foo: 'bar'}}//给组件传静态值 ] -
获取参的方式
$route.params.msg
查询参的方式$route.query.msg
-
vuex状态管理 0. 不同状态进行数据共享的时候
-
配置
{ state: {} //存放动态数据 mutations: {} //更改数据 getters: { } //计算数据 actions: { } //异步操作后才去更改数据的时候需要用到 } -
使用
- stroe.state.xx //读取
- store.getters.xx
- store.commit(xxx) //更改
- store.dispatch(xxx)
-
帮助方法
- mapState
- mapGetters
- mapMutations
- mapActions
-
模块化
-
dispatch:含有异步操作,例如向后台提交数据,
写法:this.$store.dispatch('action方法名',值)
commit:同步操作
写法:this.$store.commit('mutations方法名',值)actions异步操作时候使用的方法
-