美文网首页
web vue项目优化

web vue项目优化

作者: 时间_7436 | 来源:发表于2020-06-23 17:55 被阅读0次

vue click事件全局防抖

const on = Vue.prototype.$on;
Vue.prototype.$on = function(event, func) {
let timer,
    newFunc = func,
    switchon = true;
if (event === "click") {
    newFunc = function() {
        if (switchon) {
            func.apply(this, arguments);
            switchon = false;
        }
        clearTimeout(timer);
        timer = setTimeout(function() {
            switchon = true;
        }, 800);
    };
}
on.call(this, event, newFunc);
};

vue中的事件委托

 <!--   html  -->
  <ul  @click.stop ="handleClick($event)" v-if="array && array.length">
              <li :data-val='el.id v-for="el in array"'>{{el.name}}</li>
  </ul>

   // methods

  handleClick (data, e) {
    if (e.target.nodeName.toLowerCase() === 'li') {
      if (e.target.dataset && e.target.dataset.hasOwnProperty('val')) {
       this.getdatafn( e.target.dataset.val)
      }
    }
  },

视图通过route.meta..KeepAlive判断是否缓存组件

 <keep-alive v-if="$route.meta.KeepAlive">
        <router-view></router-view>
      </keep-alive>
      <router-view v-else></router-view>

相关文章

  • web vue项目优化

    通过自定义命令,防止短时间内多次点击调用搜索 自定义指令 vue中的事件委托 视图通过route.meta..Ke...

  • LuckyDraw幸运大抽奖(卡片、转盘、点云、幸运星)

    Introduction: 幸运抽奖Vue Web项目Luck draw Vue web project.GitH...

  • vue项目优化

    vue 项目优化 项目打包体积优化 通常vue项目通过webpack打包后,会出现vendor包的体积过大的情况,...

  • vue项目搭建

    前言 此样板为基于Vue2.0的移动web项目搭建方式。 项目构成 Vue+Vue-cli+Vue-Router+...

  • Nginx开启Gzip优化网页访问速度

    前言 开启Nginx Gzip 优化网页加载速度不限于Vue项目,所有前端皆可开启gzip优化如果是Vue项目可以...

  • vue.config.js配置

    vue cli3.x创建的项目vue本身已经做了些优化,如果想在这个优化之上在进行优化的话我们需要在项目的根目录新...

  • Vue项目性能优化

    主要分为三个方面来优化 Vue 代码层面的优化 webpack 配置层面的优化 基础的 Web 技术层面的优化 一...

  • vue相关

    vue相关 vue入门 下载vue.js 创建静态web项目 将vue.js导入项目 编写hello页面,引入vu...

  • Vue 网站首页加载优化

    Vue 网站首页加载优化 本篇主要讲解 Vue项目打包后 vendor.js 文件很大 如何对它进行优化 以及开启...

  • 博客网站首页加载优化

    Vue 网站首页加载优化 本篇主要讲解 Vue项目打包后 vendor.js 文件很大 如何对它进行优化 以及开启...

网友评论

      本文标题:web vue项目优化

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