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 }
結果