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

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

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

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">確認(rèn)發(fā)布</a-button>
    </template>
    <h1>注意事項(xiàng)</h1>
          <ol style=" listStyleType: 'decimal', paddingLeft: 12, marginTop: 10 ">
            <li>上線時(shí)間:19:00-23:00禁止(流量高峰),緊急上線聯(lián)系開(kāi)發(fā)。</li>
            <li>上線間隔:3分鐘內(nèi)只能上線一次,防止新內(nèi)容過(guò)多時(shí)執(zhí)行慢。</li>
            <li>上線成功:出現(xiàn)“上線成功”彈窗,即完成本次上線。</li>
            <li>上線頻率:少量多次,請(qǐng)勿積攢過(guò)多新內(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: '錯(cuò)誤提示',
            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">確認(rèn)發(fā)布</a-button>
    </template>
    <h1>注意事項(xiàng)</h1>
          <ol style=" listStyleType: 'decimal', paddingLeft: 12, marginTop: 10 ">
            <li>上線時(shí)間:19:00-23:00禁止(流量高峰),緊急上線聯(lián)系開(kāi)發(fā)。</li>
            <li>上線間隔:3分鐘內(nèi)只能上線一次,防止新內(nèi)容過(guò)多時(shí)執(zhí)行慢。</li>
            <li>上線成功:出現(xiàn)“上線成功”彈窗,即完成本次上線。</li>
            <li>上線頻率:少量多次,請(qǐng)勿積攢過(guò)多新內(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: '錯(cuò)誤提示',
            content: err?.response?.data?.msg || '上線失敗'
        })
        loading.value = false
        handleCancel()
     })
    }
    const handleCancel = () => {
        controlVisible.value = false
    }
    return {
       loading,
        handleOk,
        openModal,
      handleCancel,
      controlVisible
    }
  }
})
</script>

3、provide和inject

在父組件中通過(guò)provide暴露屬性或方法,子組件通過(guò)inject接受,并且只要是父組件的后代,都可以通過(guò)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">確認(rèn)發(fā)布</a-button>
    </template>
    <h1>注意事項(xiàng)</h1>
    <ol style=" listStyleType: 'decimal', paddingLeft: 12, marginTop: 10 ">
      <li>上線時(shí)間:19:00-23:00禁止(流量高峰),緊急上線聯(lián)系開(kāi)發(fā)。</li>
      <li>上線間隔:3分鐘內(nèi)只能上線一次,防止新內(nèi)容過(guò)多時(shí)執(zhí)行慢。</li>
      <li>上線成功:出現(xiàn)“上線成功”彈窗,即完成本次上線。</li>
      <li>上線頻率:少量多次,請(qǐng)勿積攢過(guò)多新內(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: '錯(cuò)誤提示',
            content: err?.response?.data?.msg || '上線失敗'
          })
          loading.value = false
          handleCancel()
        })
    }
    const handleCancel = () => {
      handle(false)
    }
    return {
      loading,
      handleOk,
      handleCancel,
      controlVisible
    }
  }
}
</script>

總結(jié)

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

相關(guān)文章

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

    Vuex的各個(gè)模塊封裝的實(shí)現(xiàn)

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

    詳解用vue編寫(xiě)彈出框組件

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

    解析VUE中nextTick是什么

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

    Vue2中集成DHTMLXGantt甘特圖的步驟

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

    vuex使用方法超詳細(xì)講解(實(shí)用)

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

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

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

    uni-app自定義組件詳細(xì)代碼示例

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

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

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

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

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

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

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

最新評(píng)論

固原市| 五大连池市| 南宫市| 汾西县| 中超| 乌鲁木齐县| 广平县| 谷城县| 古交市| 青川县| 安国市| 孟州市| 嘉黎县| 田阳县| 普兰店市| 喜德县| 灵丘县| 六安市| 栾城县| 兴化市| 方城县| 沙坪坝区| 沽源县| 厦门市| 万载县| 淅川县| 桂林市| 双江| 卢龙县| 天祝| 兴安盟| 彰武县| 博白县| 元朗区| 从江县| 比如县| 遂宁市| 开封县| 临潭县| 阜城县| 白朗县|