window跟vue变量互相绑定


js实现变量监听

    //定义一个对象,挂载到window下,后续在任何模块中,给这个对象的show属性赋值,都将触发set对应的代码,我这么写主要是为了解决vue子组件向父组件传值的问题
    window.mlistener={}
    let _this = this
    Object.defineProperty(mlistener,'show',{
      set: function(val){
        _this.showHeader = val
        _this.showFoot = val
      }
    })

 

window变量触发vue渲染

可保持window变量,跟vue用到的变量同步更新

//将window赋值给vue变量 
   data() {
      return {
        tableH: 0,
        isShow: true,
        filterText: '',
        window: window,
        tree_data: [],
        expendKeys: [],
        defaultProps: {
          children: 'children',
          label: 'label'
        }
      }

//用法
{{window.getTest()}}


//getTest()
    window.getTest = ()=>{
        console.dir(this.fullScreen)
        return this.fullScreen
    }

结果

 

 

 

 

 

参考

js监听一个变量的变化


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM