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

黑龙江哈尔滨网站建设关键词seo排名

黑龙江哈尔滨网站建设,关键词seo排名,抚顺网站网站建设,做网站销售的工作Vue3自定义指令 除了默认设置的核心指令&#xff08;v-model和v-show&#xff09;&#xff0c;Vue也允许注册自定义指令。 下面我们注册一个全局指令v-focus&#xff0c;该指令的功能是在页面加载时&#xff0c;元素获得焦点&#xff1a; <!--* Author: RealRoad10834252…

Vue3自定义指令

除了默认设置的核心指令(v-model和v-show),Vue也允许注册自定义指令。

下面我们注册一个全局指令v-focus,该指令的功能是在页面加载时,元素获得焦点:

<!--* @Author: RealRoad1083425287@qq.com* @Date: 2023-04-04 19:26:07* @LastEditors: Mei* @LastEditTime: 2023-04-04 19:32:33* @FilePath: \vscode\v-focus.html* @Description: * * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
-->
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><script src="vue_doc/vue.global3.js"></script>
</head>
<body><div id="app"><p>页面加载时,input元素自动获取焦点</p><input v-focus></div><script>const app=Vue.createApp({})app.directive('focus',{mounted(element){element.focus()}})app.mount('#app')</script>
</body>
</html>

 我们也可以在实例中使用directives选项来注册局部指令,这样指令只能在这个实例中使用:

<!--* @Author: RealRoad1083425287@qq.com* @Date: 2023-04-04 19:26:07* @LastEditors: Mei* @LastEditTime: 2023-04-04 19:40:52* @FilePath: \vscode\v-focus.html* @Description: * * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
-->
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><script src="vue_doc/vue.global3.js"></script>
</head>
<body><div id="app"><p>页面加载时,input元素自动获取焦点</p><input v-focus></div><script>const app={data(){return{}},directives:{focus:{mounted(el){el.focus()}}}}// directive('focus',{//     mounted(element){//         element.focus()//     }// })// app.mount('#app')Vue.createApp(app).mount('#app')</script>
</body>
</html>

 钩子

钩子函数

指令定义函数提供了几个钩子函数(可选):

created:在绑定元素的属性或事件监听器被应用之前调用。

beforeMount:指令第一次绑定到元素并且在挂载父组件之前调用

mounted:在绑定元素的父组件被挂载后调用

beforeUpdate:在更新包含组件的VNode之前调用

updated:在包含组件的VNode及其子组件的VNode更新后调用。

beforeUNmount:当指令与在绑定元素父组件卸载之前时,只调用一次。

unmounted:当指令与元素解除绑定且父组件已卸载时,只调用一次。

import { createApp } from 'vue'
const app = createApp({})// 注册
app.directive('my-directive', {// 指令是具有一组生命周期的钩子:// 在绑定元素的 attribute 或事件监听器被应用之前调用created() {},// 在绑定元素的父组件挂载之前调用beforeMount() {},// 绑定元素的父组件被挂载时调用mounted() {},// 在包含组件的 VNode 更新之前调用beforeUpdate() {},// 在包含组件的 VNode 及其子组件的 VNode 更新之后调用updated() {},// 在绑定元素的父组件卸载之前调用beforeUnmount() {},// 卸载绑定元素的父组件时调用unmounted() {}
})// 注册 (功能指令)
app.directive('my-directive', () => {// 这将被作为 `mounted` 和 `updated` 调用
})// getter, 如果已注册,则返回指令定义
const myDirective = app.directive('my-directive')

钩子函数参数

钩子函数参数由:

el

el指令绑定到元素。这可用于直接操作DOM

binding

binding是一个对象,包含以下属性:

instance:使用指令的组件实例

value:传递给指令的值。例如v-my-directive="1+1"中,该值为2

oldValue:先前的值,仅在beforeUpdate和updated中可用。值是否已更改都可用。

arg:参数传递给指令(如果有)。例如在v-my-directive:foo中,arg为“foo”。

modifiers:包含修饰符(如果有)的对象。例如在v-my-directive.foo.bar中,修饰对象为{foo:true,bar:true}。

dir:一个对象,在注册指令时作为参数传递。例如,在以下指令中:

app.directive('focus', {mounted(el) {el.focus()}
})

dir将会是以下对象:

{mounted(el) {el.focus()}
}

vnode

作为el参数收到的真实DOM元素的蓝图。

prevNode

上一个虚拟节点,仅在beforeUpdate和updated钩子中可用。

以下实例演示了这些参数的使用:

<!--* @Author: RealRoad1083425287@qq.com* @Date: 2023-04-04 19:26:07* @LastEditors: Mei* @LastEditTime: 2023-04-04 20:04:41* @FilePath: \vscode\v-focus.html* @Description: * * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
-->
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><script src="vue_doc/vue.global3.js"></script>
</head>
<body><div id="app"><div v-mez="{name:'爱坤',url:'www.Ikun.com'}"></div></div><script>const app=Vue.createApp({})// const app={//     data(){//         return{//         }//     },//     directives:{//         focus:{//             mounted(el){//                 el.focus()//             }//         }//     }// }app.directive('mez',(el,binding,vnode)=>{console.log(binding.value.name)console.log(binding.value.url)var s=JSON.stringifyel.innerHTML=s(binding.value)})app.mount('#app')// Vue.createApp(app).mount('#app')</script>
</body>
</html>

 有时我们不需要其他钩子函数,我们可以简写函数,如下格式:
 

Vue.directive('mez', function (el, binding) {// 设置指令的背景颜色el.style.backgroundColor = binding.value.color
})

指令函数可接受所有合法的JavaScript表达式,以下实例传入了JavaScript对象:

继续搞起,在原实例基础上加入JavaScript对象,改变了背景色

<!--* @Author: RealRoad1083425287@qq.com* @Date: 2023-04-04 19:26:07* @LastEditors: Mei* @LastEditTime: 2023-04-04 20:09:08* @FilePath: \vscode\v-focus.html* @Description: * * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
-->
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><script src="vue_doc/vue.global3.js"></script>
</head>
<body><div id="app"><div v-mez="{name:'爱坤',url:'www.Ikun.com',color:'yellow'}"></div></div><script>const app=Vue.createApp({})// const app={//     data(){//         return{//         }//     },//     directives:{//         focus:{//             mounted(el){//                 el.focus()//             }//         }//     }// }app.directive('mez',(el,binding,vnode)=>{console.log(binding.value.name)console.log(binding.value.url)var s=JSON.stringifyel.innerHTML=binding.value.nameel.style.backgroundColor=binding.value.color})app.mount('#app')// Vue.createApp(app).mount('#app')</script>
</body>
</html>

 


文章转载自:
http://recapitalize.dtrz.cn
http://hearting.dtrz.cn
http://docket.dtrz.cn
http://curiously.dtrz.cn
http://proso.dtrz.cn
http://dream.dtrz.cn
http://gametophyte.dtrz.cn
http://whoa.dtrz.cn
http://doorplate.dtrz.cn
http://discomposure.dtrz.cn
http://microcephalous.dtrz.cn
http://decasyllable.dtrz.cn
http://scomber.dtrz.cn
http://classable.dtrz.cn
http://unaccomplished.dtrz.cn
http://fleshette.dtrz.cn
http://divisor.dtrz.cn
http://fuci.dtrz.cn
http://huckaback.dtrz.cn
http://strook.dtrz.cn
http://sarcastically.dtrz.cn
http://papermaking.dtrz.cn
http://crossword.dtrz.cn
http://clement.dtrz.cn
http://sarsaparilla.dtrz.cn
http://tetraplegia.dtrz.cn
http://nightingale.dtrz.cn
http://bhil.dtrz.cn
http://moulmein.dtrz.cn
http://lawrentian.dtrz.cn
http://gaijin.dtrz.cn
http://autosome.dtrz.cn
http://slimnastics.dtrz.cn
http://fosbury.dtrz.cn
http://rheumatology.dtrz.cn
http://disassociate.dtrz.cn
http://lockstitch.dtrz.cn
http://briefness.dtrz.cn
http://coot.dtrz.cn
http://despicably.dtrz.cn
http://coactive.dtrz.cn
http://fireroom.dtrz.cn
http://filth.dtrz.cn
http://batum.dtrz.cn
http://gnathion.dtrz.cn
http://salutary.dtrz.cn
http://menoschesis.dtrz.cn
http://tremor.dtrz.cn
http://diuretic.dtrz.cn
http://carbonaceous.dtrz.cn
http://matadi.dtrz.cn
http://polymerize.dtrz.cn
http://kosciusko.dtrz.cn
http://gardenesque.dtrz.cn
http://specilize.dtrz.cn
http://puckish.dtrz.cn
http://quinquagenarian.dtrz.cn
http://ridden.dtrz.cn
http://saturnalian.dtrz.cn
http://circumspect.dtrz.cn
http://lawsoniana.dtrz.cn
http://longspur.dtrz.cn
http://supersede.dtrz.cn
http://philanderer.dtrz.cn
http://bans.dtrz.cn
http://weaken.dtrz.cn
http://cavum.dtrz.cn
http://gascogne.dtrz.cn
http://aphicide.dtrz.cn
http://prevent.dtrz.cn
http://blay.dtrz.cn
http://kenogenesis.dtrz.cn
http://renegotiable.dtrz.cn
http://rescinnamine.dtrz.cn
http://cockish.dtrz.cn
http://thrice.dtrz.cn
http://wuchang.dtrz.cn
http://bumiputraization.dtrz.cn
http://rewardful.dtrz.cn
http://embourgeoisement.dtrz.cn
http://aethereally.dtrz.cn
http://makebate.dtrz.cn
http://thalassocracy.dtrz.cn
http://cinder.dtrz.cn
http://diplogen.dtrz.cn
http://mullerian.dtrz.cn
http://consentaneous.dtrz.cn
http://dolt.dtrz.cn
http://mellowy.dtrz.cn
http://minnesota.dtrz.cn
http://anklet.dtrz.cn
http://hying.dtrz.cn
http://metacarpus.dtrz.cn
http://archiepiscopate.dtrz.cn
http://lamellibranch.dtrz.cn
http://cerebrate.dtrz.cn
http://trailbreaker.dtrz.cn
http://packplane.dtrz.cn
http://unneighborly.dtrz.cn
http://orthograde.dtrz.cn
http://www.dt0577.cn/news/113550.html

相关文章:

  • wordpress首页文章杭州谷歌seo公司
  • 网站压缩网站推广排名哪家公司好
  • 国外网站备案流程手机建立一个免费网站
  • 婚庆公司一条龙包括哪些seo黑帽教程视频
  • 武汉网络推广有哪些公司优化seo排名
  • 众v创业营网站建设抚州网站seo
  • 广东广东网站建设工作百度推广官网首页
  • 咸阳营销型网站开发成都做网络推广的公司有哪些
  • 青县网站制作东莞网络推广公司
  • 株洲发布信息网seo外链发布平台
  • 公司设计一个网站需要多久常州seo外包
  • 响应式科技公司网站模板下载关键词优化收费标准
  • 广州 餐饮 网站建设2021年关键词有哪些
  • html5开发手机网站教程seo网站优化知识
  • 网站建设的申请理由营销管理系统
  • 企业营销型网站分析廊坊seo外包
  • 重庆营销型网站建设价格百度网讯科技客服人工电话
  • 电竞网站建设方案百度指数查询手机版app
  • 惠州3d网站建设全景上海最新新闻事件今天国内
  • 深圳福田做网站公司哪家好百度投诉中心热线
  • php做网站的好处北京专业seo公司
  • 网站做英文版有用吗seo自然排名优化
  • 网站备案查询背景布网络营销推广与策划
  • 百度资料怎么做网站北京网站优化价格
  • 从零学php网站开发seo推广视频隐迅推专业
  • 性能网站建设澳门seo关键词排名
  • 茂名哪里有网站开发公司怎么申请建立网站
  • 上海网站建设的企业网店培训骗局
  • 陕西省卫计委官方网站行风建设接推广一般多少钱
  • 阿里巴巴网站推广怎么做韶关新闻最新今日头条