全局属性怎么在setup中使用#14171
-
app.config.globalProperties.msg = 'hello' |
BetaWas this translation helpful?Give feedback.
All reactions
<script setup>import { ref, getCurrentInstance } from 'vue'const instance = getCurrentInstance()console.log(instance.appContext.config.globalProperties)const msg = ref('Hello World!')</script><template> <h1>{{ msg }}</h1> <input v-model="msg" /></template>Replies: 1 comment 2 replies
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
|
BetaWas this translation helpful?Give feedback.
All reactions
-
Actually, globalProperties is a compatibility API, and I don't recommend using it. As you said, you can set global variables through the window, but you can write a hook function or use a library like Pinia to manage your global state and global variables. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Another point worth mentioning is that |
BetaWas this translation helpful?Give feedback.