为什么vue-router和Vuex不能在vue之外的生态使用呢?
大家都知道路由模式有Hash和History两种。在vue-router中也存在这两种,比如过hash模式下可以通过hashchange的方法监听路由是否改变,一旦改变在Vue中会记录变化,利用Vue的响应式机制,拿到与路由规则匹配的组件进行渲染。History提供的方法中pushState,replaceState,popstate也可以监听路由变化。 废话不多说直接上代码。
手写Vue—Router



所以在Vue-router和Vue是强耦合的,要使用Vue的响应式。
相同的情况下Vuex也是同理



Vuex其实也是使用了Vue的响应式,在data中的数据Vue会自动把数据改为响应式数据,
总结: Vue-Router和Vuex需要Vue的响应式系统进行数据的响应式处理进行变更。所以Vue-Router和Vuex不能在Vue生态外使用
网友评论