学习Vue3 第二十四章(全局变量)

253 阅读1分钟

在vue3中没有prototype属性,

定义全局变量或者函数

app.config.globalProperties.name = ' yoga'

模版中直接使用, js中通过getCurrentInstance()

<template>
  <div>{{ name }}</div>
</template>
<script setup>
import { ref, reactive, provide, getCurrentInstance } from 'vue'

const instance = getCurrentInstance()
console.log(instance.proxy.name)
</script>

<style scoped></style>