vue设置全局属性

1.vue2中设置全局

//main.js

Vue.prototype.$message = {
	name:'你好啊'
};

//页面取值
this.$message

2.vue3设置全局

//main.js
const app=createApp(App)
app.config.globalProperties.$message = {
	name:'你好啊'
};

//页面取值
import { getCurrentInstance } from "vue";
export default {
	setup() {
        let { proxy } =getCurrentInstance() //getCurrentInstance()用于获取当前组件的上下文
		console.log(proxy.$message);
    }
}

你可能感兴趣的:(vue3.0,vue.js,javascript,前端)