当前位置: 首页 > news >正文

做网做网站建设的网站外链工具xg

做网做网站建设的网站,外链工具xg,平台型网站建设预算表,固安做网站除了 Vue 内置的一系列指令 (比如 v-model 或 v-show) 之外&#xff0c;Vue 还允许你注册自定义的指令 (Custom Directives)。 1. 生命周期钩子函数 一个自定义指令由一个包含类似组件生命周期钩子的对象来定义。钩子函数会接收到指令所绑定元素作为其参数。 在 <script …

除了 Vue 内置的一系列指令 (比如 v-modelv-show) 之外,Vue 还允许你注册自定义的指令 (Custom Directives)。

1. 生命周期钩子函数

一个自定义指令由一个包含类似组件生命周期钩子的对象来定义。钩子函数会接收到指令所绑定元素作为其参数。

<script setup> 中,任何以 v 开头的驼峰式命名的变量都可以被用作一个自定义指令。

<!-- App.vue -->
<template><div><button>切换</button><!-- 钩子函数里面都可以接受这些值myParam: 自定义参数;myModifier: 自定义修饰符 --><A v-move:myParam.myModifier="{ background: 'pink' }"></A></div>
</template><script setup lang="ts">
import { reactive, ref, Directive } from 'vue';
import A from './components/A.vue';
import B from './components/B.vue';
let flag = ref<boolean>(true)
const vMove: Directive = {created() {console.log('created')},beforeMount() {console.log('beforeMount')},mounted(...args: Array<any>) {console.log('mounted')console.log(args);},beforeUpdate() {console.log('beforeUpdate')},updated() {console.log('updated')},beforeUnmount() {console.log('beforeUnmount')},unmounted() {console.log('unmounted')}
}
</script><style scoped lang="less"></style>

在这里插入图片描述

  • 0:该 div 元素。
  • 1:传入的参数等。比如 arg 参数,modifiers 自定义修饰符,dir 目录,传入的 value 值,instance 组件实例。
  • 2:当前组件的虚拟 DOM
  • 3:上一个虚拟 DOM
<!-- App.vue -->
<template><div><button>切换</button><!-- 钩子函数里面都可以接受这些值myParam: 自定义参数;myModifier: 自定义修饰符 --><A v-move:myParam.myModifier="{ background: 'pink' }"></A></div>
</template><script setup lang="ts">
import { reactive, ref, Directive, DirectiveBinding } from 'vue';
import A from './components/A.vue';
import B from './components/B.vue';
let flag = ref<boolean>(true)
type Dir = {background: string;
}
const vMove: Directive = {created() {console.log('created')},beforeMount() {console.log('beforeMount')},mounted(el: HTMLElement, dir: DirectiveBinding<Dir>) {console.log('mounted')console.log(el);console.log(dir);el.style.background = dir.value.background;},// 传入的数据发生变化(比如此时的background)时触发 beforeUpdate 和 updatedbeforeUpdate() {console.log('beforeUpdate')},updated() {console.log('updated')},beforeUnmount() {console.log('beforeUnmount')},unmounted() {console.log('unmounted')}
}
</script><style scoped lang="less"></style>

在这里插入图片描述

2. 指令简写

<!-- App.vue -->
<template><div class="btns"><button v-has-show="123">创建</button><button>编辑</button><button>删除</button></div>
</template><script setup lang="ts">
import { reactive, ref, DirectiveBinding } from 'vue';
import type { Directive } from 'vue'
const vHasShow: Directive = (el, binding) => {console.log(el, binding) ;
}
</script><style scoped lang="less">
.btns {button {margin: 10px;}
}
</style>

在这里插入图片描述

应用场景1:按钮鉴权

根据能否从 localStorage(或者后台返回) 中获取数据,来判断是否显示某个按钮。

<!-- App.vue -->
<template><div class="btns"><button v-has-show="'shop:create'">创建</button><button v-has-show="'shop:edit'">编辑</button><button v-has-show="'shop:delete'">删除</button></div>
</template><script setup lang="ts">
import { reactive, ref, DirectiveBinding } from 'vue';
import type { Directive } from 'vue'
localStorage.setItem('userId', 'xiuxiu')
// mock 后台返回的数据
const permissions = ['xiuxiu:shop:create',// 'xiuxiu:shop:edit',  // 后台没有相应数据,则不显示该对应的按钮'xiuxiu:shop:delete'
]
const userId = localStorage.getItem('userId') as string
const vHasShow: Directive = (el, binding) => {if(!permissions.includes(userId + ':' + binding.value)) {el.style.display = 'none'}
}
</script><style scoped lang="less">
.btns {button {margin: 10px;}
}
</style>

在这里插入图片描述

应用场景2:鼠标拖拽

拖拽粉色框移动大盒子。

<!-- App.vue -->
<template><div v-move class="box"><div class="header"></div><div>内容</div></div>
</template><script setup lang="ts">
import { Directive, DirectiveBinding } from 'vue';const vMove:Directive<any,void> = (el:HTMLElement, binding:DirectiveBinding)=> {let moveElement:HTMLElement = el.firstElementChild as HTMLElement;console.log(moveElement);const mouseDown = (e:MouseEvent) => {// 记录原始位置// clientX 鼠标点击位置的X轴坐标// clientY 鼠标点击位置的Y轴坐标// offsetLeft 鼠标点击的子元素距离其父元素的左边的距离// offsetTop 鼠标点击的子元素距离其父元素的顶部的距离let X = e.clientX - el.offsetLeft;let Y = e.clientY - el.offsetTop;const move = (e:MouseEvent) => {console.log(e);el.style.left = e.clientX - X + 'px';el.style.top = e.clientY - Y + 'px';}document.addEventListener('mousemove', move);document.addEventListener('mouseup', () => {document.removeEventListener('mousemove', move);})}moveElement.addEventListener('mousedown', mouseDown);
}
</script><style scoped lang="less">
.box {position: fixed;height: 200px;width: 200px;top: 50%;left: 50%;transform: translate(-50%, -50%);border: 1px solid #000;.header {height: 50px;width: 100%;background: pink;border-bottom: #000 1px solid;}
}
</style>

在这里插入图片描述

应用场景3:懒加载

let imageList = import.meta.glob('./assets/images/*.*', { eager: true })

在这里插入图片描述

let imageList = import.meta.glob('./assets/images/*.*')

在这里插入图片描述

 // 判断图片是否在可视区const observer = new IntersectionObserver((e)=> {console.log(e[0]);})  // 监听元素observer.observe(el)

在这里插入图片描述
在这里插入图片描述

<!-- App.vue -->
<template><div><div><img v-lazy="item" width="400" height="500" v-for="item in arr" alt=""></div></div>
</template><script setup lang="ts">
import { Directive, DirectiveBinding } from 'vue';let imageList:Record<string,{default:string}> = import.meta.glob('./assets/images/*.*', { eager: true })
let arr = Object.values(imageList).map(item=>item.default)
console.log(arr);
let vLazy:Directive<HTMLImageElement,string> = async (el,binding)=> {const def = await import('./assets/pinia.svg')el.src = def.default// 判断图片是否在可视区const observer = new IntersectionObserver((e)=> {console.log(e[0],binding.value);if(e[0].intersectionRatio > 0) {setTimeout(()=> {el.src = binding.value},2000)observer.unobserve(el)}})  // 监听元素observer.observe(el)
}
</script><style scoped lang="less"></style>
  1. 进入可视区比例 > 0:

    在这里插入图片描述

  2. 过 2s ,替换图片

    在这里插入图片描述


文章转载自:
http://ceaseless.mnqg.cn
http://cytologist.mnqg.cn
http://languistics.mnqg.cn
http://washboiler.mnqg.cn
http://safener.mnqg.cn
http://despatch.mnqg.cn
http://gumdrop.mnqg.cn
http://rurality.mnqg.cn
http://comprimario.mnqg.cn
http://algonquian.mnqg.cn
http://soap.mnqg.cn
http://cord.mnqg.cn
http://hanjiang.mnqg.cn
http://abstention.mnqg.cn
http://locule.mnqg.cn
http://microcode.mnqg.cn
http://puddening.mnqg.cn
http://delubrum.mnqg.cn
http://microlanguage.mnqg.cn
http://capoeira.mnqg.cn
http://ssbn.mnqg.cn
http://discolored.mnqg.cn
http://autolyse.mnqg.cn
http://hopeless.mnqg.cn
http://firstly.mnqg.cn
http://deterrence.mnqg.cn
http://factor.mnqg.cn
http://maytime.mnqg.cn
http://reconversion.mnqg.cn
http://octameter.mnqg.cn
http://wordily.mnqg.cn
http://serve.mnqg.cn
http://polyglottism.mnqg.cn
http://posadero.mnqg.cn
http://rebuke.mnqg.cn
http://lammastide.mnqg.cn
http://threnode.mnqg.cn
http://fsn.mnqg.cn
http://laureate.mnqg.cn
http://lappa.mnqg.cn
http://lithospermum.mnqg.cn
http://denationalize.mnqg.cn
http://herodlas.mnqg.cn
http://possum.mnqg.cn
http://sovran.mnqg.cn
http://atrabilious.mnqg.cn
http://masterdom.mnqg.cn
http://callout.mnqg.cn
http://politicalize.mnqg.cn
http://resole.mnqg.cn
http://chug.mnqg.cn
http://jugulation.mnqg.cn
http://regain.mnqg.cn
http://transjordania.mnqg.cn
http://bacchante.mnqg.cn
http://thereof.mnqg.cn
http://chartula.mnqg.cn
http://approximation.mnqg.cn
http://concordat.mnqg.cn
http://rantipole.mnqg.cn
http://membra.mnqg.cn
http://confrontationist.mnqg.cn
http://transsonic.mnqg.cn
http://kiloton.mnqg.cn
http://seagoing.mnqg.cn
http://photogeology.mnqg.cn
http://aftertax.mnqg.cn
http://haffir.mnqg.cn
http://fatstock.mnqg.cn
http://mercifully.mnqg.cn
http://stylohyoid.mnqg.cn
http://cymbeline.mnqg.cn
http://uprightness.mnqg.cn
http://rocambole.mnqg.cn
http://linuron.mnqg.cn
http://dingus.mnqg.cn
http://haversine.mnqg.cn
http://endoergic.mnqg.cn
http://dawdling.mnqg.cn
http://innards.mnqg.cn
http://ramark.mnqg.cn
http://oleomargarine.mnqg.cn
http://manicotti.mnqg.cn
http://uralborite.mnqg.cn
http://poikilocyte.mnqg.cn
http://tabloid.mnqg.cn
http://victimize.mnqg.cn
http://balladmonger.mnqg.cn
http://consecrate.mnqg.cn
http://unremittent.mnqg.cn
http://spectrology.mnqg.cn
http://ski.mnqg.cn
http://plurisyllable.mnqg.cn
http://wrappage.mnqg.cn
http://greenyard.mnqg.cn
http://thuswise.mnqg.cn
http://hurtling.mnqg.cn
http://ixion.mnqg.cn
http://pigtailed.mnqg.cn
http://biliary.mnqg.cn
http://www.dt0577.cn/news/112380.html

相关文章:

  • 做网站要会那些ps南通关键词优化平台
  • 如何进行电子商务网站建设网络销售怎么干
  • 公司网站在哪里做seo社区
  • 网页设计作业效果图seo检查工具
  • 如何用c语言做网站福州seo网站管理
  • 做网站销售怎么找客户新站seo优化快速上排名
  • 内蒙古网站建设流程企业网站建设多少钱
  • 网站开发服务器知识百度网站
  • 网站的维护和更新国外搜索引擎排名
  • 七米网站建设推广优化关键词查询工具哪个好
  • wordpress设计的网站企业网站有哪些功能
  • 软件开发培训机构电话seo网站诊断分析报告
  • 石家庄免费专业做网站手机建网站软件
  • 怎么把自己做的网站放上网络今日头条新闻最新疫情
  • 百度网站收录创建网站的公司
  • wordpress手机端侧边工具栏seo怎么搞
  • 怎样php网站建设百度推广关键词技巧定价
  • 网页图片另存为的时候保存不了jpg网络seo营销推广
  • 深圳做网页的网站今日足球赛事数据
  • wordpress free theme优化大师有必要安装吗
  • 日本网站空间台州seo排名外包
  • 宜昌今日头条新闻aso优化服务平台
  • 站长之家psd软文写作的三个要素
  • 定制网站建设公司百度开户渠道
  • 贵州省住房和城乡建设局网站首页网站备案信息查询
  • 百度做网站的费用网站页面优化内容包括哪些
  • 有哪些网站建设企业企业营销策划书如何编写
  • 网站推广排名教程广告公司是做什么的
  • 内网 做 网站杭州seo托管公司推荐
  • 做分销网站系统下载互联网营销师报名费