• 自定义element-ui plus 函数式调用,在API,js中直接使用全局组件


    npm方式:

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

    yarn 方式 :

    1. yarn add unplugin-vue-components;
    2. yarn add unplugin-auto-import;

     

     使用官方的这个:

    1. vite.config.js中配置
    2. plugins: [
    3. vue(),
    4. AutoImport({
    5. resolvers: [ElementPlusResolver()],
    6. }),
    7. Components({
    8. resolvers: [VantResolver(), ElementPlusResolver()],
    9. }),
    10. ],

     LoginDialog.js定义

    1. import {createApp} from 'vue'
    2. import SubDialog from './LoginDialog.vue'
    3. /**
    4. * 关键函数挂在整个页面上去
    5. */
    6. const createDialog = () => {
    7. const mountNode = document.createElement('div')
    8. mountNode.setAttribute('id', 'dialog-mask-dialog')
    9. const Instance = createApp(SubDialog, {
    10. show: true,
    11. close: () => {
    12. Instance.unmount(mountNode);
    13. document.body.removeChild(mountNode);
    14. }
    15. })
    16. document.body.appendChild(mountNode)
    17. Instance.mount(mountNode)
    18. }
    19. export default createDialog

    LoginDialog.vue 定义 

    1. <template>
    2. <Teleport to="body">
    3. <el-dialog
    4. v-model="props.show"
    5. title="登录"
    6. width="500px"
    7. center
    8. >
    9. <el-form :model="loginForm" :rules="formDataRule" ref="formRef" label-width="120px">
    10. <el-form-item label="用户名" prop="phone">
    11. <el-input v-model="loginForm.phone" placeholder="输入手机号"/>
    12. el-form-item>
    13. <el-form-item label="验证码" prop="verifyCode">
    14. <div style="display: inline-block">
    15. <el-input v-model="loginForm.verifyCode" placeholder="输入验证码"/>
    16. div>
    17. <div style="display: inline-block">
    18. <el-button>获取验证码el-button>
    19. div>
    20. el-form-item>
    21. <el-form-item>
    22. <el-button type="primary" @click="submitLogin(formRef)">登录el-button>
    23. el-form-item>
    24. el-form>
    25. el-dialog>
    26. Teleport>
    27. template>
    28. <script setup>
    29. import {reactive, ref} from "vue";
    30. const formRef = ref(null)
    31. const loginForm = reactive({
    32. phone: '',
    33. verifyCode: ''
    34. })
    35. const formDataRule = {
    36. phone: [{required: true, message: '手机号不能为空', trigger: 'blur'}],
    37. verifyCode: [{required: true, message: '验证码不能为空', trigger: 'blur'}]
    38. }
    39. const props = defineProps({
    40. show: {
    41. type: Boolean,
    42. default: false
    43. }
    44. })
    45. const submitLogin = (ref) => {
    46. ref.validate((valid) => {
    47. if (valid) {
    48. console.log('submit!')
    49. } else {
    50. console.log('error submit!')
    51. return false
    52. }
    53. })
    54. }
    55. script>
    56. <style scoped>
    57. style>

  • 相关阅读:
    多物种组织载玻片——ProSci 胰腺组织解决方案
    webpack配置杂记
    ChatGPT Word 大师
    第十八章:Swing自述
    ESP8266-Arduino编程实例-PCF8563实时时钟(RTC)驱动
    制作一个企业网站——html华为官网购物商城项目的设计与实现
    【Vue】安装并使用vue-cli搭建SPA项目
    Linux中安装Tomcat
    【Hack The Box】linux练习-- Mango
    R语言【geometry】——convhulln():计算包含一组点的最小穹顶
  • 原文地址:https://blog.csdn.net/qq_15038701/article/details/134225016