码迷,mamicode.com
首页 > 其他好文 > 详细

Vue 原理猜想

时间:2017-06-07 12:41:54      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:ble   compile   char   port   fine   pat   doctype   span   width   

<!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>

 

Vue 原理猜想

标签:ble   compile   char   port   fine   pat   doctype   span   width   

原文地址:http://www.cnblogs.com/xuezizhenchengxuyuan/p/6956139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!