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
The complete code is as follows : HTML code: Copy ...
1. Purpose Through this article, everyone can und...
Preface When we forget the MySQL database passwor...
Use the for loop to import the zabbix image into ...
Experimental environment A minimally installed Ce...
Mysql auto-increment primary key id does not incr...
This article shares the specific code for JavaScr...
Table of contents need Core Idea Two ways to impl...
Table of contents 1. Don’t treat objects as Maps ...
The solution to the problem that the PHP7.3 versi...
Table of contents chmod Example Special attention...
Detailed explanation of the order of Mysql query ...
1. Introduction to MySQL permissions There are 4 ...
Table of contents Water wave effect Let's see...
A major feature of the WeChat 8.0 update is the s...