美文网首页
vue 开发、学习遇到的问题(start-2023-10-25)

vue 开发、学习遇到的问题(start-2023-10-25)

作者: Lucky_1122 | 来源:发表于2023-12-04 23:17 被阅读0次

一、image相关

动态加载本地静态图片

// 获取assets静态资源
export const getAssetsFile = (url: string) => {
  return new URL(`../assets/${url}`, import.meta.url).href
}
 const urlStr = getAssetsFile(`image/${i + 1}.jpeg`)

1.js获取图片的宽高

const imgInfo = (url: string): Promise<ImgUrl> => {
  return new Promise((resolve) => {
    const img = new Image()
    img.src = url
    img.onload = () => {
      resolve({
        url,
        height: img.height,
        width: img.width,
      })
    }
  })
}
//调用
 const img = await imgInfo(getAssetsFile(`image/${i + 1}.jpeg`))

二、数组相关

//定义数组类型
interface ImgUrl {
  url: string
  height: number
  width: number
}
 const arr = <ImgUrl[]>[]
const list = ref<ImgUrl[]>([])
//数组初始化
 var arr_names: number[] = new Array(50)

三 遍历接口返回的字典

 Object.keys(res.data).forEach((key) => {
          const item = myMap[key]
  
        });

四、路由相关

route-link拦截

const tapAction = (event) => {
  if (props.path === '/ai-chat/chat') {
//下面两句会阻止时间继续传递,如果需要继续传递吧下面两句注释掉
    event.stopPropagation()
    event.preventDefault()
    ElMessage.error('该功能暂时供企业专版使用')
    return
  }
}

  <component :to="path" :is="path ? 'router-link' : 'div'">
    <div
      class="menu-item"
      :class="{
        'router-link-active': route.fullPath.indexOf(path as string) === 0,
      }"
      @click="tapAction($event)"
    >
      <img v-if="props.avatar" :src="props.avatar" class="menu-item__avatar" />
      <span v-else-if="isSvg" v-html="props.icon" />
      <svg-icon
        v-else-if="icon"
        :name="icon"
        :size="sizeMap[icon as keyof typeof sizeMap] ?? '22px'"
      />
      {{ name }}
    </div>
  </component>

四、纯js文件如何出现dialog

/**
大致思路:
第一步:创建一个dialog.vue 模版
第二步:创建一个dialog.js文件 ,创建个实例 const instance=createApp(rootComponent: Component, rootProps?: object)
创建一个div:( const mountNode = document.createElement('div')) 
将这个div 添加到body上: document.body.appendChild(mountNode),
然后将这个实例挂载到div上: instance.mount(mountNode)
第三步:js文件中引入dialog.js(import DialogHandle from "@/components/dialog.js";)
const handleOpenDialog = () => {
    const dialog = DialogHandle({
        title: "操作确认",
        content: "<div>是否确定删除数据?</div>",
        onConfirm: () => {
            return new Promise(async (resolve) => {
                dialog.showLoading();
                setTimeout(() => {
                    dialog.hideLoading();
                    resolve();
                }, 1500);
            });
        },
    });
};
**/


dialog参考链接:https://juejin.cn/post/7136099187057721380

相关文章

  • vue开发遇到的问题

    1.elementui table的列是动态的,数据input框更改,但是值不会变,原来是没有用$set

  • Vue2.0 生产环境部署

    简要:继上次搭建vue环境后,开始着手vue的学习;为此向大家分享从开发环境部署到生产环境(线上)中遇到的问题和解...

  • Vue 开发时间线

    Vue 开发日记第1天 安装开发环境 写登录页面 遇到的一些问题 Vue 开发日记第2天 登录跳转及路由 Vue ...

  • Vue和ElementUi组件开发遇到的问题

    Vue和ElementUi组件开发遇到的问题 一、vue 1. props单向绑定 vue中的props是单向绑定...

  • 初入uni-app遇到的问题

    本人之前是做Vue项目开发的,此篇文章是相对于vue项目转移至uni-app遇到的问题,以及对uniapp的学习~...

  • vue 学习遇到的问题

    一、接口请求(出现Request Method:OPTIONS) 首先安装axios: 1):npm insta...

  • Vue开发知识

    主要记录一些Vue开发过程中遇到的问题

  • 寒假总结

    阶段学习 vue学习 花费时间:12天(没有预期) 遇到问题: 1.vue-cli学习阶段...

  • vue项目代理配置以及遇到的问题

    vue在开发阶段解决跨域问题可以在vue.config.js里面配置: 我遇到的问题:需要切换环境的时候需要重新编...

  • Vue项目开发中遇到的问题

    点击之后,切换导航栏的icon,这时候不能直接写入相对路径,因为这时候资源已经被模块化了,如果需要将所需资源模块化...

网友评论

      本文标题:vue 开发、学习遇到的问题(start-2023-10-25)

      本文链接:https://www.haomeiwen.com/subject/uzcsidtx.html