uniapp 创建vue3项目

182 阅读1分钟

main.js详解:

import {
    createSSRApp
} from 'vue'
import App from './App.vue'
import store from '@/store/store.js'
import lang from '@/common/js/lang.js';
import util from '@/common/js/util.js';
uni.$http = lang; // 设置全局变量
uni.$util = util; // 设置全局变量
import MescrollUni from "@/components/mescroll/my-list-mescroll.vue";

// 封装弹窗方法
uni.$showMsg = function(title = '数据加载失败!', icon = 'none') {
    uni.showToast({
        title,
        duration: 1500,
        icon
    })
}

export function createApp() {
    const app = createSSRApp(App)
    app.component("mescroll-uni", MescrollUni); // 注册全局组件
    return {
        app,
        store // 使用vuex
    }
}

注册了$http之后就能在项目的位置使用了,调用uni.$http进行访问,注册的全局变量前面都要加上$符号防止命名冲突