最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue3組件式彈窗打開的3種方式小結(jié)

 更新時間:2023年07月20日 10:17:53   作者:莫奈的日出  
這篇文章主要給大家介紹了關(guān)于vue3組件式彈窗打開的3種方式,彈窗組件是常見的交互組件,它能夠彈出一些提示信息、提醒用戶進行操作等等,需要的朋友可以參考下

1、利用父子組件傳值

父組件:

<template>
  <div>
    <a-button style="margin: 20px" type="primary" @click="showModal">上線</a-button>
    <OnlineModal :controlVisible="visibleIt" @closeModal="visibleIt=false"/>
  </div>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue'
import { useRoute } from 'vue-router'
import OnlineModal from './onlineModal.vue'
export default defineComponent({
  components: {
    OnlineModal
  },
  setup() {
    const route = useRoute()
    const visibleIt = ref<boolean>(false)
    const showModal = () => {
      visibleIt.value = true
    }
    return {
      route,
      visibleIt,
      showModal
    }
  }
})
</script>
  

子組件:

<template>
  <a-modal :visible="controlVisible" title="發(fā)布上線" @ok="handleOk" @cancel="handleCancel">
    <template #footer>
      <a-button key="back" @click="handleCancel">取消</a-button>
      <a-button key="submit" type="primary" :loading="loading" @click="handleOk">確認發(fā)布</a-button>
    </template>
    <h1>注意事項</h1>
          <ol style=" listStyleType: 'decimal', paddingLeft: 12, marginTop: 10 ">
            <li>上線時間:19:00-23:00禁止(流量高峰),緊急上線聯(lián)系開發(fā)。</li>
            <li>上線間隔:3分鐘內(nèi)只能上線一次,防止新內(nèi)容過多時執(zhí)行慢。</li>
            <li>上線成功:出現(xiàn)“上線成功”彈窗,即完成本次上線。</li>
            <li>上線頻率:少量多次,請勿積攢過多新內(nèi)容,以免影響用戶流量。</li>
          </ol>
  </a-modal>
</template>
<script lang="ts">
import {  ref } from 'vue'
import {postRelease} from '@/services/online'
import { message } from 'ant-design-vue';
export default ({
  props:['controlVisible'],
  setup(props, {emit}) {
    console.log(props.controlVisible);
    const loading = ref<boolean>(false)
    const handleOk = () => {
      loading.value = true
      postRelease().then( res => {
        console.log(res, '----');
        debugger
        message.success('上線成功')
        loading.value = false
     }).catch(err => {
        message.error({
            title: '錯誤提示',
            content: err?.response?.data?.msg || '上線失敗'
        })
        loading.value = false
     })
      emit('closeModal')
    }
    const handleCancel = () => {
        emit('closeModal')
    }
    return {
       loading,
        handleOk,
      handleCancel
    }
  }
})
</script>

2、利用ref

父組件:

<template>
  <div>
    <a-button style="margin: 20px" type="primary" @click="showModal">上線</a-button>
    <OnlineModal ref="onlineModal" />
  </div>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue'
import { useRoute } from 'vue-router'
import OnlineModal from './onlineModal.vue'
export default defineComponent({
  components: {
    OnlineModal
  },
  setup() {
    const route = useRoute()
    const onlineModal = ref<boolean>(false)
    const showModal = () => {
      onlineModal.value.openModal()
    }
    return {
      route,
      showModal,
      onlineModal
    }
  }
})
</script>
  

子組件:

<template>
  <a-modal :visible="controlVisible" title="發(fā)布上線" @ok="openModal" @cancel="handleCancel">
    <template #footer>
      <a-button key="back" @click="handleCancel">取消</a-button>
      <a-button key="submit" type="primary" :loading="loading" @click="handleOk">確認發(fā)布</a-button>
    </template>
    <h1>注意事項</h1>
          <ol style=" listStyleType: 'decimal', paddingLeft: 12, marginTop: 10 ">
            <li>上線時間:19:00-23:00禁止(流量高峰),緊急上線聯(lián)系開發(fā)。</li>
            <li>上線間隔:3分鐘內(nèi)只能上線一次,防止新內(nèi)容過多時執(zhí)行慢。</li>
            <li>上線成功:出現(xiàn)“上線成功”彈窗,即完成本次上線。</li>
            <li>上線頻率:少量多次,請勿積攢過多新內(nèi)容,以免影響用戶流量。</li>
          </ol>
  </a-modal>
</template>
<script lang="ts">
import {  ref } from 'vue'
import {postRelease} from '@/services/online'
import { message } from 'ant-design-vue';
export default ({
  setup(props, {emit}) {
    const controlVisible = ref<boolean>(false)
    const loading = ref<boolean>(false)
    const openModal = () =>{
        controlVisible.value = true
    }
    const handleOk = () => {
        openModal()
      loading.value = true
      postRelease().then( res => {
        console.log(res, '----');
        debugger
        message.success('上線成功')
        loading.value = false
        handleCancel()
     }).catch(err => {
        message.error({
            title: '錯誤提示',
            content: err?.response?.data?.msg || '上線失敗'
        })
        loading.value = false
        handleCancel()
     })
    }
    const handleCancel = () => {
        controlVisible.value = false
    }
    return {
       loading,
        handleOk,
        openModal,
      handleCancel,
      controlVisible
    }
  }
})
</script>

3、provide和inject

在父組件中通過provide暴露屬性或方法,子組件通過inject接受,并且只要是父組件的后代,都可以通過inject接收到父組件暴露的值

父組件:

<template>
  <div>
    <a-button style="margin: 20px" type="primary" @click="showModal">上線</a-button>
    <OnlineModal />
  </div>
</template>
<script lang="ts">
import { defineComponent, provide, ref } from 'vue'
import { useRoute } from 'vue-router'
import OnlineModal from './onlineModal.vue'
export default defineComponent({
  components: {
    OnlineModal
  },
  setup() {
    const route = useRoute()
    const controlIfVisible = ref<boolean>(false)
    provide('controlIfVisible', controlIfVisible)
    const showModal = (sonValue) => {
      controlIfVisible.value = sonValue
    }
    provide('handle', showModal)
    return {
      route,
      showModal,
      controlIfVisible
    }
  }
})
</script>
  

子組件:

<template>
  <a-modal :visible="controlVisible" title="發(fā)布上線" @ok="handleOk" @cancel="handleCancel">
    <template #footer>
      <a-button key="back" @click="handleCancel">取消</a-button>
      <a-button key="submit" type="primary" :loading="loading" @click="handleOk">確認發(fā)布</a-button>
    </template>
    <h1>注意事項</h1>
    <ol style=" listStyleType: 'decimal', paddingLeft: 12, marginTop: 10 ">
      <li>上線時間:19:00-23:00禁止(流量高峰),緊急上線聯(lián)系開發(fā)。</li>
      <li>上線間隔:3分鐘內(nèi)只能上線一次,防止新內(nèi)容過多時執(zhí)行慢。</li>
      <li>上線成功:出現(xiàn)“上線成功”彈窗,即完成本次上線。</li>
      <li>上線頻率:少量多次,請勿積攢過多新內(nèi)容,以免影響用戶流量。</li>
    </ol>
  </a-modal>
</template>
<script lang="ts">
import { ref, inject } from 'vue'
import { postRelease } from '@/services/online'
import { message } from 'ant-design-vue'
export default {
  setup(props) {
    const loading = ref<boolean>(false)
    const controlVisible = inject('controlIfVisible')
    const handle: any = inject('handle')
    const handleOk = () => {
      handle(true)
      loading.value = true
      postRelease()
        .then((res) => {
          console.log(res, '----')
          debugger
          message.success('上線成功')
          loading.value = false
          handleCancel()
        })
        .catch((err) => {
          message.error({
            title: '錯誤提示',
            content: err?.response?.data?.msg || '上線失敗'
          })
          loading.value = false
          handleCancel()
        })
    }
    const handleCancel = () => {
      handle(false)
    }
    return {
      loading,
      handleOk,
      handleCancel,
      controlVisible
    }
  }
}
</script>

總結(jié)

到此這篇關(guān)于vue3組件式彈窗打開的3種方式的文章就介紹到這了,更多相關(guān)vue3組件式彈窗打開內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vuex的各個模塊封裝的實現(xiàn)

    Vuex的各個模塊封裝的實現(xiàn)

    這篇文章主要介紹了Vuex的各個模塊封裝的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • 詳解用vue編寫彈出框組件

    詳解用vue編寫彈出框組件

    本篇文章主要介紹了詳解用vue編寫彈出框組件,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-07-07
  • 解析VUE中nextTick是什么

    解析VUE中nextTick是什么

    nextTick是Vue提供的一個全局API,由于Vue的異步更新策略導(dǎo)致我們對數(shù)據(jù)的修改不會立刻體現(xiàn),在DOM變化上,此時如果想要立即獲取更新后的DOM狀態(tài),就需要使用這個方法,這篇文章主要介紹了解析VUE中nextTick,需要的朋友可以參考下
    2022-11-11
  • Vue2中集成DHTMLXGantt甘特圖的步驟

    Vue2中集成DHTMLXGantt甘特圖的步驟

    文章介紹了在Vue2中集成DHTMLXGantt甘特圖的步驟,涵蓋安裝、初始化、數(shù)據(jù)綁定、事件交互及常見問題解決,感興趣的朋友跟隨小編一起看看吧
    2025-08-08
  • vuex使用方法超詳細講解(實用)

    vuex使用方法超詳細講解(實用)

    這篇文章主要給大家介紹了關(guān)于vuex使用方法的相關(guān)資料,主要內(nèi)容包括Vuex的安裝和配置,以及如何在.vue文件中引入和使用Vuex狀態(tài),作者還分享了一種在模塊中存儲狀態(tài)的建議方法,并提供了具體的代碼示例,需要的朋友可以參考下
    2024-10-10
  • 深入理解Vue 的鉤子函數(shù)

    深入理解Vue 的鉤子函數(shù)

    這篇文章主要介紹了Vue 的鉤子函數(shù),本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-09-09
  • uni-app自定義組件詳細代碼示例

    uni-app自定義組件詳細代碼示例

    組件是vue技術(shù)中非常重要的部分,組件使得與ui相關(guān)的輪子可以方便的制造和共享,進而使得vue使用者的開發(fā)效率大幅提升,這篇文章主要給大家介紹了關(guān)于uni-app自定義組件的相關(guān)資料,需要的朋友可以參考下
    2024-02-02
  • Vue如何動態(tài)修改el-table的某列數(shù)據(jù)

    Vue如何動態(tài)修改el-table的某列數(shù)據(jù)

    這篇文章主要介紹了Vue如何動態(tài)修改el-table的某列數(shù)據(jù),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • 詳解Vue中$props、$attrs和$listeners的使用方法

    詳解Vue中$props、$attrs和$listeners的使用方法

    本文主要介紹了Vue中$props、$attrs和$listeners的使用詳解,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • vue中返回結(jié)果是promise的處理方式

    vue中返回結(jié)果是promise的處理方式

    這篇文章主要介紹了vue中返回結(jié)果是promise的處理方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04

最新評論

绥德县| 永康市| 广安市| 绥化市| 大化| 台东县| 道真| 墨竹工卡县| 恩施市| 天台县| 浦东新区| 平乡县| 百色市| 汨罗市| 调兵山市| 漳浦县| 波密县| 沁阳市| 河西区| 乐至县| 金堂县| 安国市| 偏关县| 海南省| 铁岭市| 丹巴县| 林西县| 白玉县| 通化市| 吉安县| 福贡县| 晋中市| 张掖市| 冀州市| 运城市| 淮阳县| 景东| 荔浦县| 新闻| 勃利县| 丰城市|