This article shares the specific code of Vue3 manual encapsulation of pop-up box component message for your reference. The specific content is as follows Package components<template> <Transition name="down"> <div class="xtx-message" :style="style[type]" v-show='isShow'> <!-- The style is bound above --> <!-- Different prompt icons will change--> <i class="iconfont" :class="[style[type].icon]"></i> <span class="text">{{text}}</span> </div> </Transition> </template> <script> import { onMounted, ref } from 'vue' export default { name: 'XtxMessage', props: { text: { type: String, default: '' }, type: { type: String, // warn warning error error success success default: 'warn' } }, setup () { // Define an object containing three styles. The object key is the type string const style = { warn: icon: 'icon-warning', color: '#E6A23C', backgroundColor: 'rgb(253, 246, 236)', borderColor: 'rgb(250, 236, 216)' }, error: { icon: 'icon-shanchu', color: '#F56C6C', backgroundColor: 'rgb(254, 240, 240)', borderColor: 'rgb(253, 226, 226)' }, success: { icon: 'icon-queren2', color: '#67C23A', backgroundColor: 'rgb(240, 249, 235)', borderColor: 'rgb(225, 243, 216)' } } // Control animation const isShow = ref(false) // Trigger onMounted(() => { isShow.value = true }) return { style, isShow } } } </script> <style scoped lang="less"> .down { &-enter { &-from { transform: translate3d(0, -75px, 0); opacity: 0; } &-active { transition: all 0.5s; } &-to { transform: none; opacity: 1; } } } .xtx-message { width: 300px; height: 50px; position: fixed; z-index: 9999; left: 50%; margin-left: -150px; top: 25px; line-height: 50px; padding: 0 25px; border: 1px solid #e4e4e4; background: #f5f5f5; color: #999; border-radius: 4px; i { margin-right: 4px; vertical-align: middle; } .text { vertical-align: middle; } } </style> Mounted on the prototype object of Vue // The following method needs to render a prompt effect import { createVNode, render } from 'vue' import XtxMessage from './xtx-message.vue' // Dynamically create a DOM container const div = document.createElement('div') div.setAttribute('class', 'xtx-meassage-container') document.body.appendChild(div) export default ({ text, type }) => { let timer = null // createVNode is used to create a virtual node // Parameter 1 supports the component // Parameter 2 represents the options passed to the component const vnode = createVNode(XtxMessage, { text, type }) // Render the virtual node into the DOM of the page // Parameters of the render function // Parameter 1: indicates the content to be rendered (virtual node) // Parameter 2: indicates the target location of rendering (DOM element) render(vnode, div) // Hope the prompt message will disappear after 1 second clearTimeout(timer) timer = setTimeout(() => { // Clear the contents of div render(null, div) }, 1000) } // $message({ text: 'Login failed', type: 'error'}) import Message from './Message' export default { install(app) { // If you want to mount global properties, you can call the property this.$message through the component instance app.config.globalProperties.$message = Message // prototype function} } useone. import Message from '@/components/library/Message' setup () { // Trigger login const handleLogin = async () => { // Manual form validation const flag = await target.value.validate() if (flag) { // Verification passed, call the interface to log in // If the login fails, prompt Message({ type: 'error', text: 'Login failed' }) } } mounted () { this.$message({ type: 'error', text: 'Login failed' }) } } two. // Get the instance object of the component: similar to the previous this const instance = getCurrentInstance() // Click to log in const handleLogin = async () => { const valid = await target.value.validate() if (valid) { // Form verification passed, call the interface to log in // Message({ text: 'Login failed', type: 'error' }) instance.proxy.$message({ text: 'Login failed', type: 'error' }) } } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
>>: Excel export always fails in docker environment
After the official release of Activiti7, it has f...
This article shares the summary of the JS mineswe...
Configure the accelerator for the Docker daemon S...
The mini program collected user personal informat...
1. Docker cross-host communication Docker cross-h...
Scenario: When page A opens page B, after operati...
html Copy code The code is as follows: <SPAN cl...
As a front-end novice, I tinkered with the front-e...
Install fastdfs on Docker Mount directory -v /e/f...
1. Download MySQL Community Server 5.7.16 and ins...
will-change tells the browser what changes will h...
This article shares the specific method of instal...
Operation effect: html <!-- This element is no...
Preface The general methods are not listed here, ...
Although I have run some projects in Docker envir...