import {
createApp } from 'vue';
import App from './App.vue';
const app = createApp(App);
app.mount('#app');
以下例子用于解释在vue3.0的main.js中挂载公共的方法(foo)
import {
createApp } from 'vue';
import App from './App.vue';
import foo from '@/foo';
const app = createApp(App);
app.config.globalProperties.$foo = foo;
app.mount('#app');
在页面中使用,这里只针对使用了setup语法糖的使用者
<templant>
<div></div>
</templant>
<script setup>
import {
getCurrentInstance } from 'vue';
const {
proxy } = getCurrentInstance ();
proxy.$foo()
</script>