-
zhangwei
2025-03-05 16213c0f85aa3ac8317797bf4a05fd12940e16d3
src/uni_modules/uview-plus/index.js
@@ -77,11 +77,48 @@
    platform
}
// $u挂载到uni对象上
uni.$u = $u
export const mount$u = function() {
    uni.$u = $u
}
// #ifdef H5
const importFn = import.meta.glob('./components/u-*/u-*.vue', { eager: true })
let components = [];
// 批量注册全局组件
for (const key in importFn) {
    let component = importFn[key].default;
    if (component.name && component.name.indexOf('u--') !== 0) {
        component.install = function (Vue) {
            Vue.component(name, component);
        };
        // 导入组件
        components.push(component);
    }
}
// #endif
function toCamelCase(str) {
    return str.replace(/-([a-z])/g, function(match, group1) {
      return group1.toUpperCase();
    }).replace(/^[a-z]/, function(match) {
      return match.toUpperCase();
    });
}
const install = (Vue) => {
    // #ifdef H5
    components.forEach(function(component) {
        const name = component.name.replace(/u-([a-zA-Z0-9-_]+)/g, 'up-$1');
        Vue.component(name, component);
    });
    // #endif
    // 同时挂载到uni和Vue.prototype中
    // $u挂载到uni对象上
    uni.$u = $u
    // #ifndef APP-NVUE
    // 只有vue,挂载到Vue.prototype才有意义,因为nvue中全局Vue.prototype和Vue.mixin是无效的
    Vue.config.globalProperties.$u = $u