欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue3+ts+elementui-plus二次封裝彈框?qū)崙?zhàn)教程

 更新時間:2023年07月27日 11:52:48   作者:suoh's Blog  
這篇文章主要介紹了vue3+ts+elementui-plus二次封裝彈框?qū)崙?zhàn)教程,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

vue3+ts+elementui-plus二次封裝彈框

一、彈框組件BaseDialog

<template>
      <div class='main'>
            <el-dialog v-model="visible" :title="title" :width="dialogWidth" :before-close="handleClose">
                  <!-- 內(nèi)容插槽 -->
                  <slot></slot>
                  <template #footer>
                        <span class="dialog-footer">
                              <el-button v-if="showCancelButton" @click="handleClose">取消</el-button>
                              <el-button v-if="showConfirmButton" type="primary" @click="handleConfirm">
                                    確認(rèn)
                              </el-button>
                        </span>
                  </template>
            </el-dialog>
      </div>
</template>
<script lang='ts' setup>
import { ElMessageBox } from 'element-plus'
import { ref, reactive, getCurrentInstance, onMounted, defineExpose, defineEmits } from 'vue'
/**
 * 傳入的props變量
*/
const props = defineProps({
      title: {
            type: String,
            default: '提示',
      },
      dialogWidth: {
            type: String,
            default: '40%',
      },
      showCancelButton: {
            type: Boolean,
            default: true,
      },
      showConfirmButton: {
            type: Boolean,
            default: true,
      },
})
/**
 * 發(fā)射給父組件的方法 
 * 用于子組件給父組件傳值或調(diào)用父組件方法
*/
const emits = defineEmits(['submit', 'close'])
const visible = ref(false)
// 關(guān)閉彈框
const handleClose = () => {
      emits('close')
}
// 打開彈框
const handleOpen = () => {
      visible.value = true
}
// 確認(rèn)事件
const handleConfirm = () => {
      emits('submit')
}
/**
 * 暴露給父組件的方法
 * 用于父組件調(diào)用子組件方法或獲取子組件屬性值
*/
defineExpose({ handleOpen, handleClose, visible })
onMounted(() => {
})
</script>
<style scoped lang='scss'>
</style>

二、在index.vue中使用

<el-button @click="showDialog">點(diǎn)擊出現(xiàn)彈框</el-button>
		<BaseDialog ref="baseDialog" @submit="handleSubmit" @close="handleClose">
			<div>
				<el-input placeholder="Please input" />
			</div>
		</BaseDialog>
<script lang='ts' setup>
import BaseDialog from '@/components/BaseDialog/index.vue'
import { ref, reactive, getCurrentInstance, onMounted } from 'vue'
onMounted(() => {
})
// 獲取子組件的ref
let baseDialog = ref()
// 點(diǎn)擊出現(xiàn)彈框
const showDialog = () => {
	// 調(diào)用子組件方法,打開彈框
	baseDialog.value.handleOpen()
}
// 彈框確認(rèn)事件
const handleSubmit = () => {
	console.log('我是父組件中的確認(rèn)事件')
}
// 彈框取消事件 
const handleClose = () => {
	baseDialog.value.visible = false
}
</script>

三、效果

 創(chuàng)建vue3+ts+element-plus項(xiàng)目

一、創(chuàng)建vue3項(xiàng)目

1.新建vue3TsElement文件夾

該文件夾中打開命令行窗口,運(yùn)行創(chuàng)建vue3項(xiàng)目的命令

npm init vue@latest

2.打開創(chuàng)建好的vue3_TS_element文件夾

關(guān)掉之前的命令行窗口,在該文件夾中再次打開命令行窗口下載依賴文件

npm install

3.說明

注意創(chuàng)建項(xiàng)目命令行窗口與安裝依賴命令行窗口之間的切換

二、安裝element-plus組件庫

安裝命令

npm install element-plus --save

完整引入

在main.ts引入,就可以使用了

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
app.use(ElementPlus)

按需引入

(1)首先要安裝element-plus

npm install element-plus --save

(2)然后你需要安裝unplugin-vue-components 和 unplugin-auto-import這兩款插件

npm install -D unplugin-vue-components unplugin-auto-import

(3)然后把下列代碼插入到你的 Vite 或 Webpack 的配置文件中

import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
//按需引入element
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        AutoImport({//按需引入element
            resolvers: [ElementPlusResolver()],
        }),
        Components({//按需引入element
            resolvers: [ElementPlusResolver()],
        }),
        vue(),
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    }
})

到此這篇關(guān)于vue3+ts+elementui-plus二次封裝彈框的文章就介紹到這了,更多相關(guān)vue3 ts elementui-plus彈框內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 分享12個Vue開發(fā)中的性能優(yōu)化小技巧(實(shí)用!)

    分享12個Vue開發(fā)中的性能優(yōu)化小技巧(實(shí)用!)

    一般來說,你不需要太關(guān)心vue的運(yùn)行時性能,它在運(yùn)行時非???但付出的代價是初始化時相對較慢,下面這篇文章主要給大家分享介紹了十二個Vue開發(fā)中的性能優(yōu)化小技巧,需要的朋友可以參考下
    2022-02-02
  • vue實(shí)現(xiàn)背景圖片鋪滿整個屏幕(適配所有機(jī)型)

    vue實(shí)現(xiàn)背景圖片鋪滿整個屏幕(適配所有機(jī)型)

    在網(wǎng)頁設(shè)計中,背景全屏是一種常見的視覺效果,通過正確的CSS樣式設(shè)置,可以實(shí)現(xiàn)背景全屏且內(nèi)容在固定一屏大小內(nèi)完全顯示,如果內(nèi)容超出一屏,則可以通過滾動條查看剩余內(nèi)容,這種設(shè)計可以提升用戶的瀏覽體驗(yàn),使網(wǎng)頁看起來更加整潔和專業(yè)
    2024-10-10
  • vue3中hooks的概述及用法小結(jié)

    vue3中hooks的概述及用法小結(jié)

    這篇文章是介紹一下vue3中的hooks以及它的用法,主要圍繞兩點(diǎn)來介紹,一個是hooks基本概念,另一個是vue3中hooks的使用方法,本文結(jié)合實(shí)例代碼給大家講解的非常詳細(xì),需要的朋友參考下吧
    2023-03-03
  • 解決Vue使用bus總線時,第一次路由跳轉(zhuǎn)時數(shù)據(jù)沒成功傳遞問題

    解決Vue使用bus總線時,第一次路由跳轉(zhuǎn)時數(shù)據(jù)沒成功傳遞問題

    這篇文章主要介紹了解決Vue使用bus總線時,第一次路由跳轉(zhuǎn)時數(shù)據(jù)沒成功傳遞問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • VUE3中watch和watchEffect的用法詳解

    VUE3中watch和watchEffect的用法詳解

    本文主要介紹了VUE3中watch和watchEffect的用法詳解,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • 詳解Vite如何處理CSS預(yù)處理器

    詳解Vite如何處理CSS預(yù)處理器

    在現(xiàn)代前端開發(fā)中,CSS 預(yù)處理器如 Sass、Less 和 Stylus 等工具,為樣式編寫提供了更強(qiáng)大的功能和更好的開發(fā)體驗(yàn),本文將探討 Vite 是如何處理 CSS 預(yù)處理器的,以及如何在實(shí)際項(xiàng)目中配置和使用它們,需要的朋友可以參考下
    2025-02-02
  • vue3集成Element-Plus之全局導(dǎo)入和按需導(dǎo)入

    vue3集成Element-Plus之全局導(dǎo)入和按需導(dǎo)入

    這篇文章主要給大家介紹了關(guān)于vue3集成Element-Plus之全局導(dǎo)入和按需導(dǎo)入的相關(guān)資料,element-plus正是element-ui針對于vue3開發(fā)的一個UI組件庫,?它的使用方式和很多其他的組件庫是一樣的,需要的朋友可以參考下
    2023-07-07
  • vue如何關(guān)閉eslint檢測(多種方法)

    vue如何關(guān)閉eslint檢測(多種方法)

    我們在開發(fā)vue項(xiàng)目的時候,創(chuàng)建的時候可能會不小心選擇了eslint,所以如果不想讓eslint檢測,我們該怎么辦呢,本文就詳細(xì)的介紹了幾種關(guān)閉方法,感興趣的可以了解一下
    2021-12-12
  • 詳解服務(wù)端預(yù)渲染之Nuxt(介紹篇)

    詳解服務(wù)端預(yù)渲染之Nuxt(介紹篇)

    這篇文章主要介紹了詳解服務(wù)端預(yù)渲染之Nuxt(介紹篇),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-04-04
  • 詳解vue靜態(tài)資源打包中的坑與解決方案

    詳解vue靜態(tài)資源打包中的坑與解決方案

    本篇文章主要介紹了詳解vue靜態(tài)資源打包中的坑與解決方案,本文主要解決路徑問題,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-02-02

最新評論