Vue3.x 用 Composition API 中是没有this的,所以不能直接使用 this 调用 globalProperties 全局变量
Composition API 使用方法
// main.js
import { createApp } from 'vue'
import App from './App.vue'
import storage from './plugins/storage'
const app = createApp(App);
app.config.globalProperties.$storage = storage
app.provide('$storage', storage)
app.mount('#app')
// Home.vue
import {inject} from "vue"
const storage = inject('$storage')
storage.setItme('name','zhangsan')
Vue2.x 的使用方法
// main.js
import { createApp } from 'vue'
import App from './App.vue'
import storage from './plugins/storage'
const app = createApp(App);
app.config.globalProperties.$storage = storage
app.mount('#app')
// Home.vue
this.$storage.setItme('name','zhangsan')
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net