您可以使用 uni-popup 实现自定义全局 modal,只需在 App.vue 中引入并注册即可,无需在每个页面中引入。如果您需要在 modal 中放置 input 等组件,可以在 modal 中使用 slot,如下所示:

在 App.vue 中:

<template>
  <view>
    <uni-popup ref="popup" position="center">
      <slot name="content"></slot>
    </uni-popup>
  </view>
</template>

<script>
import UniPopup from '@/components/uni-popup/uni-popup.vue'

export default {
  components: {
    UniPopup
  }
}
</script>

在其他组件中使用:

<template>
  <view>
    <button @click="showPopup">显示弹窗</button>
    <template #content>
      <view>
        <input placeholder="请输入内容"></input>
      </view>
    </template>
  </view>
</template>

<script>
export default {
  methods: {
    showPopup() {
      this.$refs.popup.show()
    }
  }
}
</script>

这样就可以实现自定义全局 modal,并在其中放置 input 等组件,同时兼容微信小程序

用 uniapp 自定义全局modal可以放input等组件uni-popup不行需要页面引入我不想页面引入需要兼容微信小程序

原文地址: http://www.cveoy.top/t/topic/fian 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录