Vue3全局屬性app.config.globalProperties的實現(xiàn)
一、概念
一個用于注冊能夠被應用內(nèi)所有組件實例訪問到的全局屬性的對象。點擊【前往】訪問官網(wǎng)

二、實踐
2.1、定義
在main.ts文件中設置app.config.globalPropertie
import {createApp} from 'vue'
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router'
import Pagination from '@/components/Pagination/index.vue';
const app = createApp(App);
//全局方法
app.config.globalProperties.$type = '類型';
app.component('Pagination', Pagination)
app.use(router);
app.use(ElementPlus);
app.mount('#app');
2.2、使用
在Vue文件中使用getCurrentInstance(),通過proxy.$type就可以調(diào)用上面定義的方法
<template>
<el-input v-model="proxy.$type" />
<template>
<script setup>
import { getCurrentInstance } from "vue";
const { proxy } = getCurrentInstance();
console.log(proxy.$type)
</script>
三、最后
到此這篇關(guān)于Vue3全局屬性app.config.globalProperties的實現(xiàn)的文章就介紹到這了,更多相關(guān)Vue3 app.config.globalProperties內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
element中el-autocomplete的常見用法示例
這篇文章主要給大家介紹了關(guān)于element中el-autocomplete的常見用法的相關(guān)資料,文中通過實例代碼介紹的非常詳細,對大家學習或者使用element具有一定的參考學習價值,需要的朋友可以參考下2023-03-03
一文詳解vue3項目實戰(zhàn)中的接口調(diào)用
在企業(yè)開發(fā)過程中,往往有著明確的前后端的分工,前端負責接收、使用接口,后端負責編寫、處理接口,下面這篇文章主要給大家介紹了關(guān)于vue3項目實戰(zhàn)中的接口調(diào)用的相關(guān)資料,需要的朋友可以參考下2022-12-12

