目前我正在將window.innerWidth值存儲到一個被調用的 vuex getterscreenWidth并在我的所有組件中使用它。但問題是每次我想使用它時,我都必須 1) import { mapGetters } from 'vuex'2)...mapGetters()在計算屬性中調用。為了擺脫這個問題,我認為原型注入可能是一個好主意。所以我這樣做了:Vue.prototype.$screenWidth = window.innerWidth;window.addEventListener('resize', () => { Vue.prototype.$screenWidth = window.innerWidth;});但這不起作用。如何更輕松地訪問組件中的屏幕寬度而無需通過所有導入/映射內容?
在 vue 組件中訪問屏幕寬度
一只斗牛犬
2021-06-28 08:49:30