zoukankan      html  css  js  c++  java
  • Vue 原理猜想

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
        <div id="app">
    
        </div>
    
        <script>
    
            function Vue(option){
    
                var _this = this
                var template =  option.template
    
                //here
                this.render = function(dom){
                    document.querySelector(option.el).innerHTML = dom
                }
    
                var data = option.data
    
                for(key in data) {
                    var initValue = data[key]
                    Object.defineProperty(this, key, {
                        set: function (val) {
                            var compileValue = template.replace("{{" + key + "}}", val)
                            _this.render(compileValue)
    //                        change notify
                        },
                        configurable: true
                    })
    
                    Object.defineProperty(data, key, {
                        set: function (val) {
                            var compileValue = template.replace("{{" + key + "}}", val)
                            _this.render(compileValue)
    //                        change notify
                        },
                        configurable: true
                    })
    
                    this[key] = initValue
                }
            }
    
            var data = {
                message:'xxxx'
            }
    
    
            var vm = new Vue({
                el:'#app',
                data:data,
                template:'<h1>{{message}}<h1>'
            })
    
            data.message = 1
            vm.message = 2
    
        </script>
    </body>
    </html>
  • 相关阅读:
    37.1 net-- udp传输
    37 net 网络编程
    review
    java day02 记录
    36.2 线程生命周期
    36.1 线程锁
    36 Thread 多线程
    35 编码 ASCII Unicode UTF-8 ,字符串的编码、io流的编码
    34.6 Properties(k,v存储) 和io流结合使用
    今日学习总结
  • 原文地址:https://www.cnblogs.com/xuezizhenchengxuyuan/p/6956139.html
Copyright © 2011-2022 走看看