SOURCE

console 命令行工具 X clear

                    
>
console
const data = {
  text:'',
  _text: ''
}
var textDom = document.querySelector('#text')
var inputDom = document.querySelector('#input')

Object.defineProperty(data, 'text', {
  get(){
    return this._text
  },
  set(val){
    this._text = val
    textDom.innerText = this._text
    inputDom.value = this._text
  }
})

document.querySelector('#input').addEventListener('keyup', function(e){
  data.text = e.target.value
  textDom.innerText = data._text
})
<input type="text" id="input" />
<p id="text"></p>