首页 > 其他 > 详细

简单实现VUE的双向数据绑定

时间:2018-11-27 13:32:13      阅读:116      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html>
<head>
	<title>vue-双向数据绑定的简单实现</title>
</head>
<body>
	<input type="text" name="" id="inputText">
	<span id=‘textSpan‘></span>
	<script type="text/javascript">
	let obj = {},
		inputText = document.querySelector(‘#inputText‘),
		textSpan = document.querySelector(‘#textSpan‘)
	Object.defineProperty(obj, ‘foo‘, {
		set: function (newValue) {
			inputText.value = newValue
			textSpan.innerHTML = newValue
		}
	})
	inputText.addEventListener(‘keyup‘, function (e) {
		obj.foo = e.target.value
	})
	</script>
</body>
</html>

  

简单实现VUE的双向数据绑定

原文:https://www.cnblogs.com/maggie-pan/p/10025803.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!