vue3移动端脚手架(纯净,集成丰富)

概述

一个纯净的移动端框架 ,用到了 Vue3 + vuex + Vite3 + Vant3 + sass + eslint + stylelint + htmlhint + husky + commitlint axios + axios-adapter + VConsole + 自定义全局 loading ,自定义函数式 dialog (api模仿微信小程序),非常适合做脚手架。

详细

框架demo介绍

Vue3 + vuex + Vite3 + Vant3
sass
eslint + stylelint + htmlhint
husky + commitlint
axios + axios-adapter
VConsole(with custom plugin)
Custom components: loading
Custom components: dialog (api模仿微信小程序)

是一个纯净的前端框架,集成丰富,适合做二次开发。

代码目录结构

代码目录结构

示例代码

定义api(同时可以定义mock数据,可自己写mock逻辑)

    static login(params?: any) {
        return this.post({
          url: `/login`,
          params: params,
          statusCode: 200,
          getJsonPath() {
            const loginSuccess = import('./mock/login/login.json')
            const loginFail = import('./mock/login/loginFail.json')
            // 可以自己写逻辑判断返回不同的mock
            return loginSuccess
          }
        })
      }
    // 实现的核心代码(方便定义api的时候顺便定义mock数据)
    ![](/contentImages/image/20220805/GZzd31UCRK8Euvz0WLe.png)
    // 利用动态导入,避免非mock状态下,加载太多mock数据

使用函数式对话框

    // api 参考微信小程序 https://developers.weixin.qq.com/miniprogram/dev/api/ui/interaction/wx.showModal.html
    showModal({
        content: '测试内容',
        // showCancel: false
      })

效果截图
 

    // 实现思路
    import { createVNode, render } from "vue"
    import modal from './modal.vue'
    // 创建一个容器,用来放dialog
    const div = document.createElement('div')
    div.setAttribute('class', 'global_modal_container')
    document.body.appendChild(div)
    // 定义好输入
    export type ModalConfig = {
      title?: string,
      content: string,
      showCancel?: boolean,
      cancelText?: string,
      confirmText?: string,
      confirm?: Function,
      cancel?: Function,
      div?: HTMLDivElement,
    }
    export default (modalConfig: ModalConfig) => {
      return new Promise((resolve, reject) => {
        const confirm = () => {
            // 根据点击时间,把内容设置为null,达到取消弹窗的效果。
          render(null, div)
          resolve(true)
        }
        const cancel = () => {
          render(null, div)
        }
        // 判断如果没有回调,那么会返回Promise对象
        if (!modalConfig.confirm) {
          modalConfig.confirm = confirm
        }
        if (!modalConfig.cancel) {
          modalConfig.cancel = cancel
        }
        modalConfig.div = div
        const vnode = createVNode(modal, modalConfig)
        render(vnode, div)
      })
    }

dialog

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西安未央

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值