当前位置: 首页 > news >正文

投诉网站怎么做/软文广告经典案例分析

投诉网站怎么做,软文广告经典案例分析,做信息类网站怎么赚钱,anylink wordpress写在前面 前段时间面试,MVVM原理成为了一道必考题。由于理解不够深,最近详细了解以结构图流程分析原理。 一原型图解 使用MVVM双向绑定 定义双向绑定,传入元素,和数据。var vm new MVVM({el: #mvvm-app,data: {someStr: hello ,c…

写在前面

前段时间面试,MVVM原理成为了一道必考题。由于理解不够深,最近详细了解以结构图流程分析原理。

一原型图解

使用MVVM双向绑定

  • 定义双向绑定,传入元素,和数据。
var vm = new MVVM({el: '#mvvm-app',data: {someStr: 'hello ',className: 'btn',htmlStr: '<span style="color: #f00;">red</span>',child: {someStr: 'World !'}}
});
复制代码

MVVM类

  • 新建劫持数据
  • 编译绑定数据
class MVVM {constructor(options) {this.$options = options || {};var data = this._data = this.$options.data;Object.keys(data).forEach(key => {this._proxyData(key);})//数据劫持observe(data, this);//编译this.$compile = new Compile(options.el || document.body, this);}_proxyData(key, setter, getter) {Object.defineProperty(this, key, {configurable: false,enumerable: true,get: function proxyGetter() {return this._data[key];},set: function proxySetter(newVal) {this._data[key] = newVal;}})}
}
复制代码

Compile类

  • 将真实DOM移动到虚拟DOM中
  • 解析元素中的指令
  • 指令新建订阅传入更新函数
class Compile {constructor(el, vm) {this.$vm = vm;this.$el = this.isElementNode(el) ? el : document.querySelector(el);if (this.$el) {//生成文档碎片this.$fragment = this.node2Fragment(this.$el);//编译this.init()//文档碎片加回容器中this.$el.appendChild(this.$fragment);}}node2Fragment(el) {var fragment = document.createDocumentFragment(),child;while (child = el.firstChild) {fragment.appendChild(child);         };return fragment;}init() {this.compileElement(this.$fragment);}compileElement(el) {        var childNodes = el.childNodes;[].slice.call(childNodes).forEach(node => {var text = node.textContent;var reg = /\{\{(.*)\}\}/;if(this.isElementNode(node)){//指令解析this.compile(node);}else if(this.isTextNode(node) && reg.test(text)){this.compileText(node, RegExp.$1)}if(node.childNodes && node.childNodes.length){this.compileElement(node);}})}compile(node){var nodeAttrs = node.attributes;[].slice.call(nodeAttrs).forEach(attr => {var attrName = attr.name;if(this.isDirective(attrName)){var exp = attr.value;var dir = attrName.substring(2);//事件指令if(this.isEventDirective(dir)){compileUtil.eventHandler(node, this.$vm, exp, dir);}else{compileUtil[dir] && compileUtil[dir](node, this.$vm, exp);}node.removeAttribute(attrName);}})}isDirective(attr){return attr.indexOf('v-') === 0;}isEventDirective(attr){return attr.indexOf('on') === 0;}isElementNode(node) {return node.nodeType == 1;}isTextNode(node) {return node.nodeType == 3;}compileText(node, exp) {compileUtil.text(node, this.$vm, exp);}
}//指令处理集合
var compileUtil = {...
}var updater = {...
}
复制代码

Observer类

  • 劫持数据
  • 数据变化通知Watcher
//数据劫持
class Observer {constructor(data) {this.data = data;this.walk(data);}walk(data) {Object.keys(data).forEach(key => {this.convert(key, data[key]);})}convert(key, val) {this.defineReactive(this.data, key, val);}//绑定数据,添加发布订阅,核心**defineReactive(data, key, val) {var dep = new Dep();var childObj = observe(val);Object.defineProperty(data, key, {enumerable: true, //可枚举configurable: false, //不能再defineget: function(){if(Dep.target){console.log(Dep.target, 'Dep.target');dep.depend();}return val;},set: function(newVal){             if(newVal === val){return;}                val = newVal;// 新的值object的话,进行监听childObj = observe(newVal);console.log(newVal);//通知订阅者dep.notify();}})}
}function observe(value, vm) {if (!value || typeof value !== 'object') {return;}return new Observer(value);
}复制代码

Dep类

  • 发布订阅类
var uid = 0;
class Dep {constructor() {this.id == uid++;this.subs = [];}addSub(sub) {this.subs.push(sub);}depend() {Dep.target.addDep(this)}removeSub(sub) {this.subs.remove(sub);}notify() { this.subs.forEach(sub => {sub.update();})}
}Dep.target = null;
复制代码

Watcher类

  • 监控数据变化,发布消息,执行订阅函数。
class Watcher{constructor(vm, expOrFn, cb){this.cb = cb;this.vm = vm;this.expOrFn = expOrFn;this.depIds = {};if(typeof expOrFn === 'function') {this.getter = expOrFn;}else{this.getter = this.parseGetter(expOrFn);}this.value = this.get();}update(){this.run();}run(){var value = this.get();var oldVal = this.value;if (value !== oldVal) {this.value = value;this.cb.call(this.vm, value, oldVal);}}get(){Dep.target = this;var value = this.getter.call(this.vm, this.vm);Dep.target = null;return value;}parseGetter(exp){if(/[^\w.$]/.test(exp)) return;var exps = exp.split(',');return function(obj) {for (let i = 0; i < exps.length; i++) {if(!obj) return;obj = obj[exps[i]];}return obj;}}addDep(dep){if (!this.depIds.hasOwnProperty(dep.id)) {dep.addSub(this);this.depIds[dep.id] = dep;}}
}
复制代码
http://www.jmfq.cn/news/5086315.html

相关文章:

  • 做网站第一次见客户/百度非企渠道开户
  • 手把手教你做网站视频/指数函数图像及性质
  • wordpress整站密码访问/谷歌商店下载
  • 网站的折线图怎么做/优化大师下载电脑版
  • 哪个网站可以做立体字的模板/seo推广外包
  • wordpress的前端怎么写/如何优化关键词排名到首页
  • 子网站怎么做/营销说白了就是干什么的
  • 网站首页滚动图片用dw怎么做/百度推广开户费用多少
  • 外包一个企业网站多少钱/武汉seo搜索引擎优化
  • 如何备份wordpress网站/互动营销案例
  • 兰州网站制作培训班/宁波网站优化公司价格
  • 百度做公司网站需要多少钱/学网络营销有用吗
  • 济宁市兖州区城市建设局网站/网络营销网站有哪些
  • 西安市招聘网最新招聘信息/网络推广优化招聘
  • 郑州网站开发公/百度网首页登录入口
  • 长沙口碑好网站建设/游戏推广文案
  • 微信微网站是什么格式的/软文推广案例
  • 山东卓商网站建设公司/网站内容优化怎么去优化呢
  • 政府网站集约化建设建议/相似图片在线查找
  • 怎么做网站赚钱吗/什么平台打广告比较好免费的
  • 深圳网站如何制作/百度搜索推广的定义
  • 阿里巴巴怎么做公司网站/官网建站多少钱
  • 网站建设 沈阳/搜索引擎营销与seo优化
  • 大型网站开发项目合同/竞价外包代运营公司
  • 广州个性化网站建设/谷歌搜索网页版入口
  • 独立网站需要怎么做/在线培训系统app
  • 招聘做微信公众号网站维护/seo查询5118
  • 霍山做网站/企业邮箱
  • 做怎么网站收费/谷歌seo怎么做
  • 网络游戏网站网址大全/如何免费搭建自己的网站