zoukankan      html  css  js  c++  java
  • vue的中vuex为何需要mutation更新状态,vue-router的路由的理解

    /**
    * action是异步,mutation是同步
    * vuex中使用commit来修改state的原因解析
    * 开启严格模式,仅需在创建 store 的时候传入 strict: true;
    * 在严格模式下,无论何时发生了状态变更且不是由 mutation 函数引起的,将会抛出错误。这能保证所有的状态变更都能被调试工具跟踪到。
    * 通过commit提交mutation修改state的值,ue的调试工具能够记录每,可以跟踪记录state的变化,直接修改state不能跟踪变化
    */

    /**
    * Vue-Router有二种——————hash、history二种方式
    * hash可以调用window的对象监听这个事件,通过监听hash的值的变化,页面发生变化,没有进行浏览器的请求
    *
    * */
    window.onhashchange = function (event) {
    let hash = location.hash.slice(1);
    document.body.style.color = hash;
    }

    /**
    * histoty 的api给前端很多自由可以实现二大部分,切换和修改
    * */
    // 切换历史记录
    history.go(-2);
    history.go(2);
    history.back();
    history.forward();
    // 修改历史,包括二个方法pushState、replaceState二个方法(objState,title,url)
    history.replaceState({ color: 'red' }, 'red', 'red');
    window.onpopstate = function (event) {
    if (event.state && event.state.color === 'red') {
    document.body.style.color = 'red';
    }
    }
    // history怕什么,怕刷新,不怕前进和后退,怕h5刷新,刷新就进行了http请求,服务器接收不到,就会返回404,所以需要服务器端配置
  • 相关阅读:
    ASP.NET应用程序与页面生命周期
    阻塞分析
    性能和异常日志
    solr 搜索引擎及搜索推荐应用
    solr 搜索引擎
    分布式缓存地址
    Windows平台分布式架构实践
    职责链模式vs状态模式区别
    HBase
    单例模式
  • 原文地址:https://www.cnblogs.com/yayaxuping/p/9924507.html
Copyright © 2011-2022 走看看