vue3에서 element-plus의 대화 상자를 사용하는 방법
장점
눈에 보이고 반복되는 돔의 번거로운 네이밍을 없애세요.
Idea
대화 상자를 함수에 의해 호출될 수 있는 구성 요소로 캡슐화하세요. 다음과 같습니다.
addDialog({ title: "测试", //弹窗名 component: TestVue, //组件 width: "400px", //弹窗大小 props: { //传给组件的参数 id: 0 }, callBack: (data: any) => { //当弹窗任务结束后,调用父页面的回掉函数。(比如我新增完成了需要刷新列表页面) console.log("回调函数", data) } })
el-dialog 기반의 예비 캡슐화
// index.ts import { reactive } from "vue" type dialogOptions = { title: string component: any props?: Object width: string visible?: any callBack?: Function } export const dialogList: dialogOptions[] = reactive([]) export const addDialog = (options: dialogOptions) => { dialogList.push(Object.assign(options, { visible: true })) } export const closeDialog = (item: dialogOptions, i: number, args: any) => { dialogList.splice(i, 1) item.callBack && item.callBack(...args) }
<template> <Teleport to="body"> <el-dialog v-for="(item, index) in dialogList" :key="index" :title="item.title" :width="item.width" v-model="item.visible" > <component :is="item.component" v-bind="item.props" @close="(...args:any) => closeDialog(item, index, args)" /> </el-dialog> </Teleport> </template> <script setup lang="ts"> import { dialogList, closeDialog } from "./index" </script>
먼저 모든 팝업 창의 정보를 담고 있는DialogList를 정의합니다.
comComponent 컴포넌트를 사용하면 하위 컴포넌트를 동적으로 로드할 수 있습니다.
addDialog 팝업 창을 불러오는 함수 호출
closeDialog 팝업 창을 닫는 함수
Mount
<script setup> import Mydialog from "@/components/gDialog/index.vue" </script> <template> <router-view /> <Mydialog></Mydialog> </template> <style scoped> </style>
app.vue
사용팝업 창 구성 요소 만들기
<!-- test.vue -->
<template>
父弹窗
<el-button type="primary" @click="openChildDialog">打开子dialog</el-button>
<el-button type="primary" @click="closeDialog">关闭弹窗</el-button>
</template>
<script setup lang="ts">
import { addDialog } from "@/components/gDialog/index"
import childVue from "./child.vue"
const props = defineProps(["id"])
console.log(props.id, "props")
const emit = defineEmits(["close"])
const closeDialog = () => {
emit("close", 1, 2, 34)
}
const openChildDialog = () => {
addDialog({
title: "我是子dialog",
width: "500px",
component: childVue
})
}
</script>
로그인 후 복사
목록 페이지에서 팝업 창 깨우기<!-- test.vue --> <template> 父弹窗 <el-button type="primary" @click="openChildDialog">打开子dialog</el-button> <el-button type="primary" @click="closeDialog">关闭弹窗</el-button> </template> <script setup lang="ts"> import { addDialog } from "@/components/gDialog/index" import childVue from "./child.vue" const props = defineProps(["id"]) console.log(props.id, "props") const emit = defineEmits(["close"]) const closeDialog = () => { emit("close", 1, 2, 34) } const openChildDialog = () => { addDialog({ title: "我是子dialog", width: "500px", component: childVue }) } </script>
<!-- list.vue -->
<template>
列表页
<el-button type="primary" @click="openDialog">打开dialog</el-button>
</template>
<script setup lang="ts">
import { addDialog } from "@/components/gDialog/index"
import TestDialog from "./test.vue"
const openDialog = () => {
addDialog({
title: "我是dialog",
width: "500px",
props:{
id:0
}
component: TestDialog,
callBack: (data: any) => {
//当弹窗任务结束后,调用父页面的回掉函数。(比如我新增完成了需要刷新列表页面)
console.log("回调函数", data)
}
})
}
로그인 후 복사
다단계 팝업 창 중첩🎜<!-- list.vue --> <template> 列表页 <el-button type="primary" @click="openDialog">打开dialog</el-button> </template> <script setup lang="ts"> import { addDialog } from "@/components/gDialog/index" import TestDialog from "./test.vue" const openDialog = () => { addDialog({ title: "我是dialog", width: "500px", props:{ id:0 } component: TestDialog, callBack: (data: any) => { //当弹窗任务结束后,调用父页面的回掉函数。(比如我新增完成了需要刷新列表页面) console.log("回调函数", data) } }) }
<!-- child.vue --> <template> 子弹窗 <el-button type="primary" @click="closeDialog">关闭弹窗</el-button> </template> <script setup lang="ts"> import { addDialog } from "@/components/gDialog/index" const emit = defineEmits(["close"]) const closeDialog = () => { emit("close", 1, 2, 34) } </script>
위 내용은 vue3에서 element-plus의 대화 상자를 사용하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











vue 및 Element-plus를 통해 테이블 편집 기능 및 행 선택을 구현하는 방법 소개: 테이블은 웹 애플리케이션을 개발할 때 자주 사용되는 구성 요소 중 하나입니다. 테이블 편집 가능성 및 행 선택 기능은 매우 일반적이고 실용적인 요구 사항입니다. Vue.js 프레임워크에서는 Element-plus 컴포넌트 라이브러리를 결합하여 이 두 기능을 쉽게 구현할 수 있습니다. 이 기사에서는 Vue 및 Element-plus를 통해 테이블 편집 가능성 및 행 선택 기능을 구현하는 방법을 소개하고 해당 코드 예제를 제공합니다. 1. 프로젝트의 정확성

Vue 및 ElementPlus를 사용하여 단계별 양식 및 양식 확인을 구현하는 방법 웹 개발에서 양식은 가장 일반적인 사용자 상호 작용 구성 요소 중 하나입니다. 복잡한 양식의 경우 단계별 채우기 및 양식 확인 기능을 수행해야 하는 경우가 많습니다. 이 기사에서는 Vue 및 ElementPlus 프레임워크를 사용하여 이 두 가지 기능을 구현하는 방법을 소개합니다. 1. 단계별 양식 단계별 양식은 큰 양식을 여러 개의 작은 단계로 나누는 것을 의미하며, 사용자는 단계에 따라 단계를 채워야 합니다. Vue의 구성요소화 및 라우팅을 활용할 수 있습니다.

vue3+vite:src는 require를 사용하여 이미지를 동적으로 가져오고 vue3+vite는 여러 이미지를 동적으로 가져옵니다. vue3을 사용하는 경우 require는 이미지를 사용할 수 없습니다. imgUrl:require(' .../assets/test.png') 와 같은 vue2는 typescript가 require를 지원하지 않기 때문에 가져오므로 이를 해결하는 방법은 다음과 같습니다. waitimport를 사용합니다.

Vue 및 ElementPlus를 사용하여 파일 업로드 및 다운로드 기능을 구현하는 방법 소개: 웹 애플리케이션에서는 파일 업로드 및 다운로드 기능이 매우 일반적입니다. 이 기사에서는 Vue 및 ElementPlus를 사용하여 파일 업로드 및 다운로드 기능을 구현하는 방법을 소개합니다. 샘플 코드를 통해 Vue와 ElementPlus를 사용하여 이러한 기능을 구현하는 방법을 쉽고 직관적으로 이해할 수 있습니다. 1. Vue 프로젝트에 ElementPlus를 설치하고 가져옵니다.

페이지를 부분적으로 새로 고치려면 로컬 구성 요소(dom)의 다시 렌더링만 구현하면 됩니다. Vue에서 이 효과를 얻는 가장 쉬운 방법은 v-if 지시어를 사용하는 것입니다. Vue2에서는 v-if 명령을 사용하여 로컬 DOM을 다시 렌더링하는 것 외에도 새 빈 구성 요소를 만들 수도 있습니다. 로컬 페이지를 새로 고쳐야 할 경우 이 빈 구성 요소 페이지로 점프한 다음 다시 돌아올 수 있습니다. 빈 원본 페이지의 beforeRouteEnter 가드. 아래 그림과 같이 Vue3.X에서 새로 고침 버튼을 클릭하여 빨간색 상자 안에 DOM을 다시 로드하고 해당 로딩 상태를 표시하는 방법입니다. Vue3.X의 scriptsetup 구문에 있는 구성 요소의 가드에는

Vue 및 ElementPlus를 사용하여 메시지 알림 및 팝업 프롬프트를 구현하는 방법 소개: 웹 애플리케이션 개발에서 메시지 알림 및 팝업 프롬프트는 매우 중요한 기능 중 하나입니다. 널리 사용되는 프런트엔드 프레임워크인 Vue는 우수한 UI 라이브러리인 ElementPlus와 결합되어 다양한 팝업 프롬프트 및 메시지 알림 기능을 쉽게 구현할 수 있습니다. 이 글에서는 Vue 프로젝트에서 ElementPlus 컴포넌트 라이브러리를 사용하여 메시지 알림 및 팝업 프롬프트 기능을 구현하고 관련 코드 예제를 첨부하는 방법을 소개합니다.

Vue 및 ElementPlus를 사용하여 데이터 내보내기 및 인쇄 기능을 구현하는 방법 최근 프런트 엔드 개발의 급속한 발전으로 인해 점점 더 많은 웹 애플리케이션에서 데이터 사용에 대한 사용자의 다양한 요구를 충족시키기 위해 데이터 내보내기 및 인쇄 기능을 제공해야 합니다. . 널리 사용되는 JavaScript 프레임워크인 Vue는 ElementPlus 구성 요소 라이브러리와 함께 사용하면 데이터 내보내기 및 인쇄 기능을 쉽게 구현할 수 있습니다. 이 문서에서는 데이터 내보내기 및

최종 효과는 VueCropper 컴포넌트 Yarnaddvue-cropper@next를 설치하는 것입니다. 위의 설치 값은 Vue2이거나 다른 방법을 사용하여 참조하려는 경우 공식 npm 주소: 공식 튜토리얼을 방문하세요. 컴포넌트에서 참조하고 사용하는 것도 매우 간단합니다. 여기서는 해당 컴포넌트와 해당 스타일 파일을 소개하기만 하면 됩니다. 여기서는 import{userInfoByRequest}from'../js/api만 소개하면 됩니다. 내 구성 요소 파일에서 import{VueCropper}from'vue-cropper&
