VUE3项目问题处理

1、子路由跳转后刷新页面报错找不到资源问题
	主要出现在cli创建的项目中 因为index.html中引入资源的路由问题  不要用  ./ 用  /
	但vite的就可以用 ./
2、iframe内嵌页面 出现灰边问题 
在iframe标签上加上配置

style="overflow: visible;"  frameborder="0"  marginwidth="0" marginheight="0"

<iframe  :src="item"  style="overflow: visible;"  frameborder="0"  marginwidth="0" marginheight="0" ></iframe>
3、封装防抖节流
---方法 
// 节流
export  const throttle=(fn, time)=> {
    let timer = null
    time = time || 1000
    return function(...args) {
        if (timer) {
            return
        }
        const _this = this
        timer = setTimeout(() => {
            timer = null
        }, time)
        fn.apply(_this, args)
    }
}

// 防抖
export const debounce=(fn, time)=> {
    time = time || 200
    // 定时器
    let timer = null
    return function(...args) {
        const _this = this;
        if (timer) {
            clearTimeout(timer)
        }
        timer = setTimeout(function() {
            timer = null
            fn.apply(_this, args)
        }, time)
    }
}
const sss = debounce(()=>{
  console.log(111) 这里写正常的函数逻辑
},2000)
页面引入后 使用


4、文件流导出excel

res为文件流数据

    let fileData = res;
    const url = window.URL.createObjectURL(
      new Blob([fileData], {
        type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8",
      })
    );
    const link = document.createElement("a");
    link.href = url;
    link.setAttribute("download", "用户信息-学生"); // 下载文件的名称及文件类型后缀
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link); // 下载完成移除元素
    window.URL.revokeObjectURL(url); // 释放掉blob对象
5、cli+vue3+js 融入 ts
vue add typescript 执行此命令

需要注意的是 第三项要选No 不然js文件会被替换为ts文件
以及融入后 部分组件将无法使用

在这里插入图片描述

6/ts变量声明
类比于项目中的CONFIG
在main.ts中引用会报错
全局创建文件  type.d.ts
在tsconfig.json中引用

type.d.ts中声明  
declare const CONFIG:any
如果是对象中属性

在这里插入图片描述
7、使用iframe框架,当在一个页面退出登录后,另一个页面点击菜单出现登录页嵌套在iframe中

在登录页面中,添加js判断,如果不是顶层框架跳转到登录页面
$(function(){
	login.initPage();
});
var login = {
	//初始化页面跳转,为了防止从iframe跳转到login页面直接在iframe中显示login页面
	initPage : function() {
		//alert(location.href);
		if(window.top != window.self){
			top.location.href = location.href;
		}
	},
}


3.0项目直接在api的js判断中添加 top.location.href = '/'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值