设置

js文件统一管理全局变量
方法1 app provide() 全局提供变量

通过inject()使用



方法2

app实例配置全局变量
获取 通过 getCurrentInstance.appContext.config.globalProperties.$innerWidth访问到


code
import { ref } from 'vue'
export const useGlobalState = () => {
const innerWidth = ref(window.innerWidth)
window.addEventListener('resize', () => {
innerWidth.value = window.innerWidth
})
return { innerWidth }
}




![[线程与网络] 网络编程与通信原理(五): 深入理解网络层IP协议与数据链路层以太网协议](https://img-blog.csdnimg.cn/direct/cd1641748acd4a98affbb7c6bce0e529.png)














