2***@qq.com
- 发布:2024-08-26 14:11
- 更新:2024-08-28 10:31
- 阅读:407
你好, 小程序不支持动态注册组件,只能在main.js中静态注册组件,全局注册。
// 注册全局组件
for (let com in components) {
app.component(com, components[com]);
console.log(app);
}
调整为
// main.js
const app = createSSRApp(App);
app.use(uviewPlus);
app.component('globalModal', modal);
app.component('navbar', navbar);
2***@qq.com (作者)
<template>
<view class="modal-container">
<up-modal :show="modelValue" :title="title">
<template v-slot:default>
<view class="content">{{ content }}</view>
</template>
<template v-slot:confirmButton>
<view class="button-box">
<view class="cancel themeBorder" @click="cancel"> 取消 </view>
<view class="save themeBorder" @click="confirm">确认</view>
</view>
</template>
</up-modal>
</view>
</template>
<script setup>
const props = defineProps({
title: {
default: '温馨提示'
},
modelValue: {
type: Boolean
},
content: {
default: '确认删除吗?'
}
});
const emits = defineEmits(['update:modelValue', 'confirm', 'update:value']);
function confirm() {
emits('update:modelValue', false);
emits('confirm');
}
function cancel(params) {
emits('update:modelValue', false);
}
2024-08-26 14:19
2***@qq.com (作者)
只是一个有确认和取消的弹出层,但是在微信小程序中这个弹出层点确认和取消都无效
2024-08-26 14:20
BFC
提供一下完整的可运行的demo吧, 你的代码看不到父组件,我这边用类似的代码自测没什么问题
2024-08-26 14:24
2***@qq.com (作者)
回复 BFC: 不好意思 demo提供不了 父组件值传递了一个v-model的字段 上面的代码就是子组件
2024-08-26 17:11
2***@qq.com (作者)
Reply DCloud_UNI_BFC: <modal v-model="showModal" @confirm="confirm"></modal>父组件是这样编写的 const showModal = ref(false)
2024-08-26 17:14
BFC
回复 2***@qq.com: 你好,你用hbuilderX新建一个demo工程,然后把上面的代码整合到工程里,然后上传一下demo的zip压缩包
2024-08-26 18:12
2***@qq.com (作者)
回复 BFC: 您看一下 已上传
2024-08-27 09:17