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

自定义指令Custom Directives

<script setup lang='ts'>
import { ref } from "vue"const state = ref(false)/*** Implement the custom directive* Make sure the input element focuses/blurs when the 'state' is toggled*
*/
// 以v开头的驼峰式命名的变量都可以作为一个自定义指令
const VFocus = {mounted:(el)=>el.focus(), // el是指令绑定到的元素updated:(el,binding)=>{ // 包含传递给指令的值、指令修饰符modifiers(v-directive.upper)、指令参数arg(v-directive:foo)等属性binding.value ? el.focus() : el.blur()}
}setInterval(() => {state.value = !state.value
}, 2000)</script><template><input v-focus="state" type="text">
</template>

自定义指令的对象提供了7个钩子函数:

created、beforeMounted、 mounted、 beforeUpdate、updated、beforeUnmount、unmounted

大多数情况仅需要使用mounted和updated。

对比vue的8个生命周期:

beforeCreate、created、beforeMount、mounted、beforeUpdate、updated、beforeUnmount、unmounted

http://www.lryc.cn/news/261435.html

相关文章:

  • 预测性维护对制造企业设备管理的作用
  • 华为、新华三、锐捷常用命令总结
  • 链路追踪详解(四):分布式链路追踪的事实标准 OpenTelemetry 概述
  • Node.js 工作线程与子进程:应该使用哪一个
  • python matplotlib 三维图形添加文字且不随图形变动而变动
  • Ubuntu设置kubelet启动脚本关闭swap分区
  • MySQL数据库存储
  • verilog语法进阶,时钟原语
  • 案例069:基于微信小程序的计算机实验室排课与查询系统
  • C语言:将三个数从大到小输出
  • 基于Hadoop的铁路货运大数据平台设计与应用
  • Java基础题2:类和对象
  • 冒泡排序学习
  • LeetCode(65)LRU 缓存【链表】【中等】
  • 网站提示“不安全”
  • 【Linux】驱动
  • Java研学-HTML
  • SpringBoot之响应的详细解析
  • redis:四、双写一致性的原理和解决方案(延时双删、分布式锁、异步通知MQ/canal)、面试回答模板
  • 智能优化算法应用:基于动物迁徙算法3D无线传感器网络(WSN)覆盖优化 - 附代码
  • illuminate/database 使用 五
  • 武汉灰京文化:益智游戏的教育与娱乐完美结合
  • arcgis api for js 中的query实现数据查询
  • AcWing 1250. 格子游戏(并查集)
  • CSS对文本的简单修饰
  • C++17中if和switch语句的新特性
  • 极坐标下的牛拉法潮流计算57节点MATLAB程序
  • 软件设计师——计算机网络(三)
  • 【ArkTS】循环控制与List的使用
  • 条款3:尽量使用const