V-model 기본 원리(important)

2410 단어 vue
Document

const xgx = new Xgx({ el: '#app', data: { msg: 'haha', eve: ' ' }, methods: { handle() { this.eve = ' ' } } }) function Xgx(option) { this.el = option.el; this.tmp = document.querySelector(this.el); for(let key in option.methods) { this[key] = option.methods[key] } for (let key in option.data) { Object.defineProperty(this, key, { get() { return option.data[key] }, set(val) { for(let i = 0; i < this.tmp.children.length; i++) { if(key == this.tmp.children[i].getAttribute('x-text')) { console.log(this.tmp.children[i]); this.tmp.children[i].innerText = val; } } option.data[key] = val; } }) } for(let i = 0; i < this.tmp.children.length; i++) { if(this.tmp.children[i].getAttribute('x-text')) { const key = this.tmp.children[i].getAttribute('x-text') this.tmp.children[i].innerText = this[key]; } if(this.tmp.children[i].getAttribute('@click')) { this.tmp.children[i].onclick = this.handle.bind(this); } } } // =function(){ } // , ---》 const obj = {}; Object.defineProperty(obj, 'abc', { //val abc , set(val) { // , console.log(this['abc']); console.log(' '); }, get() { // return 'ls' } }) console.log(obj); // var vm = new Vue({ el: '#app', // vue , data ,Object.defineProperty created(){} mounted() {} data: { msg: 'ls', obj: { name: 'ls' } }, methods: { hand() { // this.obj.age = 20; this.$set(this.obj, 'age', 20) } } // methods obj });

좋은 웹페이지 즐겨찾기