新版相关技术与协作开发安排分享

新版相关技术与协作开发安排分享

  • 老版本存在的问题

老版本存在的问题

  • 登录需要加载的初始化文件太多,导致登录页很慢(借助Vue路由懒加载+Webpack打包+Es6(动态加载)机制解决)
  • 代码不太规范,使用工具压缩编译不太理想(Eslint(代码检查)+Es6(语法))
  • 使用 Jquery ,页面主要是Dom驱动的,Dom操作安规。(Vue数据驱动解决)
  • 开发方式还是传统模式,前端工程化和自动化无法使用工具去实现(使用Nodejs平台,Npm+Webpack+Vue全家桶解决)

前端工程化和自动化,可以大大提高工作效率(上线和测试加快,研发是肯定的)

新版技术栈

  • Vue全家桶 Vue + Vuex + Vue-Router
  • Es6 + Stylus 支持
  • 主要工具 Axios (Ajax请求)Webpack(打包)
  • 前端服务器 Nodejs平台 Express框架+Webpack (实现热加载)

基本原理

  • 整个前端Mv-Vm思想

    |A|B|C|

—— ————————

前端模型层

——————————-

后端

  • Vue 组件(Components)思想,也是整个系统的 V层 视图层

    这里完成 Css Html 和 组件相关自己的数据操作(简单展现逻辑和组件之间数据传递)与组件所需的数据暴露

    高效渲染的原理图(把一个普通 Javascript 对象传给 Vue 实例的 Data 选项,Vue 将遍历此对象所有的属性,并使用 Object.Defineproperty 把这些属性全部转为 Getter/Setter。Object.Defineproperty 是仅 Es5 支持,且无法 Shim 的特性,这也就是为什么 Vue 不支持 Ie8 以及更低版本浏览器的原因。)

  • Vue-Router (有Vm,也就是Control 但是我觉Vm在整个系统中流转)

    这里完成组件的跳转和数据传递的操作,我们自己完成一个这样路由很简单,但是Vue-Router还有很多用处(我们暂时就结合Es6和Webpack完成了Js动态加载(什么时候用什么时候去取))

  • Vuex
    • 这里是我们前后端共同协作的最主要的地方,也就是上面说的前端模型层(相当于M)由一个单一状态树对象缓存.绝大部分的Dom展现与消失都依赖于这里的数据变化(数据变化是由于用户的操作与Http请求的交互)

      大家看图之后应该很明白

      Action

      Action 是异步的 ,返回的值是一个 Promise对象

      • 与后端接口最紧密的就是Action这块,这里就是前段的M层与后端接口交互的地方,
        • 这里会处理一些业务逻辑后封装成初步的M层的状态对象,再把封装的初步的状态对象 Commit()(提交给)Mutations

上面是后端能够帮助我们前端工作的地方,写相关接口和Action


  • 通过Mtation再去挂载和修改状态对象(Mutation是改变State的唯一路径,不能直接去改变State值)

    • 在通过改变的State去改变 Vue组件,再去渲染视图

下面就借着系统,说明一下上面的具体实现

接口声明

注册Store (State,Mution,Action,Getter)


通过这个改变State

相关组件或Store触发 Mution(Commit),Action(Dispath)改变State State与Getter作用于渲染视图

通过这个来触发注册的Action,进行相关组件和数据的初始化操作

/* Helvetica Neue Demo css to show basic, more technical styling Visit http://www.ulyssesapp.com/styles for full reference */ * { -webkit-text-size-adjust: none; -webkit-font-smoothing: antialiased; text-rendering: optimizelegibility !important; } body {font-size: 13pt;color:#222;background:#fbfbfb;font-family:"Helvetica Neue", Arial, Helvetica, sans-serif;line-height: 1.4;margin: 10%;} h1, h2, h3, h4, h5, h6 {font-weight:normal;color:#111;} h1 {font-size:3em;line-height:1;margin-bottom:0.5em;margin-top:2em;} h2 {font-size:2em;margin-bottom:0.75em;margin-top:1.5em;} h3 {font-size:1.5em;line-height:1;margin-top:1.5em;} h4 {font-size:1.2em;line-height:1.25;margin-bottom:1.25em;} h5 {font-size:1em;font-weight:bold;margin-bottom:1.5em;} h6 {font-size:1em;font-weight:bold;} h1 img, h2 img, h3 img, h4 img, h5 img, h6 img {margin:0;} img {max-width: 100%;} p {margin:0 0 1.5em;} a:focus, a:hover {color:#09f;} a {color:#06c;text-decoration:underline;} blockquote {margin:1.5em;color:#666;} strong, dfn {font-weight:bold;} em, dfn {font-style:italic;} del {color:#666;} pre {margin:1.5em 0;white-space:pre;} pre, code, tt {font:1em 'andale mono', 'lucida console', monospace;line-height:1.5;} li ul, li ol {margin:0;} ul, ol {margin:0 3em 1.5em 1.5em;padding-left:1.5em;} ul {list-style-type:disc;} ol {list-style-type:decimal;} figure {margin: 1.5em 0; width: 100%; text-align: center; } figcaption {font-size: 0.75em;padding:0.5em 2em;margin-bottom: 2em;} figure img {margin-bottom: 0px;} code {font-family: Menlo, monospace; font-size:90%;} p > code {padding:0.2em 0.4em; background:#e1e9ed;} pre {text-align:left; overflow-x: scroll; color: #d3bd7e; background: #202020; padding: 10pt 15pt; border-radius: 3px;} hr {border: 0px; border-top: 1px solid #ddd; border-bottom: 1px solid #fff;margin-top: 4em;margin-bottom: 2em;} h1 + hr {margin-top: 2em;} ol#footnotes {font-size: 0.75em;padding-top: 1.5em;margin-top: 3em;margin-left: 0;} ol#footnotes:before {content: "———"; letter-spacing: -4px;margin-left: -1.5em;} ol p, ul p {margin-bottom: 0px;} li {margin-bottom: 0.75em;margin-top: 0.75em;} @keyframes highfade { 0% { background-color: none; } 20% { background-color: yellow; } 100% { background-color: none; } } @-webkit-keyframes highfade { 0% { background-color: none; } 20% { background-color: yellow; } 100% { background-color: none; } } a:target, ol#footnotes li:target, sup a:target { animation-name: highfade; animation-duration: 2s; animation-iteration-count: 1; animation-timing-function: ease-in-out; -webkit-animation-name: highfade; -webkit-animation-duration: 2s; -webkit-animation-iteration-count: 1; -webkit-animation-timing-function: ease-in-out; } a:target {border:0;outline: 0;} @media screen and (max-width: 768px) { body { margin:30px; } } @media screen and (max-width: 736px) { body { margin:20px; } ul,ol { margin: 0; } h1 { font-size: 2em; } h2 { font-size: 1.8em; } }

Vue学习

一、ES6学习

阮一峰写的一本书 《ECMAScript 6入门》
也可以购置纸质书籍

二、 Vue学习

Vue作者 提供了一份 vue学习顺序 大家可以根据这个顺序去查看Vue2.0的文档就行 ,文档讲的很清楚,很容易懂的

三、webpack学习

这是我找的一片入门学习文章了解基本配置就好,感兴趣可以继续深入学习

Vue里面相关webpack配置说明
这篇文章很好的说明了Vue的三个 相关于 webpack配置文件的用处

四、SASS学习

阮一峰大神的文章 看完就可以了,如果很感兴趣 可继续看sass官方文档。

五、项目环境搭建

1.获取项目

svn获取即可,获取之后的项目是没有node_moudles的,需要下面的初始化命令才行

npm install

使用sass 有两种 scss 和 sass scss和css语法很像但是可以编程 SASS和 python比较像 不适用{}花括号 使用缩进 感觉使用缩进大家接触的很少,所以我觉得大家使用 scss 语法模式,更容易习惯

webpack只支持 sass 不支持scss 需要继续安装 一些插件来补坑

npm install node-sass sass-loader —D
再在 style 标上使用的语言