当前位置:网站首页>Atguigu---16-custom instruction
Atguigu---16-custom instruction
2022-06-24 08:02:00 【Zhangshao】
List of articles
Custom Instruction Summary :
One 、 Definition grammar :
(1). Local command :
new Vue({ new Vue({
directives:{ Instruction name : Configuration object } or directives{ Instruction name : Callback function }
}) })
(2). Global instructions :
Vue.directive( Instruction name , Configuration object ) or Vue.directive( Instruction name , Callback function )
Two 、 Commonly used in configuration objects 3 A callback :
(1).bind: Called when the instruction successfully binds to the element .
(2).inserted: Called when the element of the instruction is inserted into the page .
(3).update: Called when the template structure of the instruction is re parsed .
3、 ... and 、 remarks :
1. Instructions are defined without v-, But use it with v-;
2. If the instruction name is more than one word , To use kebab-case Naming method , Do not use camelCase name .
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title> Custom instruction </title>
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!-- demand 1: Define a v-big Instructions , and v-text The function is similar to , But it will enlarge the bound value 10 times . demand 2: Define a v-fbind Instructions , and v-bind The function is similar to , But you can make it bound input Element gets focus by default . Custom Instruction Summary : One 、 Definition grammar : (1). Local command : new Vue({ new Vue({ directives:{ Instruction name : Configuration object } or directives{ Instruction name : Callback function } }) }) (2). Global instructions : Vue.directive( Instruction name , Configuration object ) or Vue.directive( Instruction name , Callback function ) Two 、 Commonly used in configuration objects 3 A callback : (1).bind: Called when the instruction successfully binds to the element . (2).inserted: Called when the element of the instruction is inserted into the page . (3).update: Called when the template structure of the instruction is re parsed . 3、 ... and 、 remarks : 1. Instructions are defined without v-, But use it with v-; 2. If the instruction name is more than one word , To use kebab-case Naming method , Do not use camelCase name . -->
<!-- Prepare a container -->
<div id="root">
<h2>{
{name}}</h2>
<h2> Current n The value is :<span v-text="n"></span> </h2>
<!-- <h2> Zoom in 10 After times n The value is :<span v-big-number="n"></span> </h2> -->
<h2> Zoom in 10 After times n The value is :<span v-big="n"></span> </h2>
<button @click="n++"> Am I n+1</button>
<hr/>
<input type="text" v-fbind:value="n">
</div>
</body>
<script type="text/javascript"> Vue.config.productionTip = false // Define global instructions /* Vue.directive('fbind',{ // When an instruction is successfully bound to an element ( at first ) bind(element,binding){ element.value = binding.value }, // When the element of the instruction is inserted into the page inserted(element,binding){ element.focus() }, // When the template of the instruction is parsed again update(element,binding){ element.value = binding.value } }) */ new Vue({
el:'#root', data:{
name:' Silicon Valley ', n:1 }, directives:{
//big When will the function be called ?1. When an instruction is successfully bound to an element ( at first ).2. When the template of the instruction is parsed again . /* 'big-number'(element,binding){ // console.log('big') element.innerText = binding.value * 10 }, */ big(element,binding){
console.log('big',this) // Pay attention to this yes window // console.log('big') element.innerText = binding.value * 10 }, fbind:{
// When an instruction is successfully bound to an element ( at first ) bind(element,binding){
element.value = binding.value }, // When the element of the instruction is inserted into the page inserted(element,binding){
element.focus() }, // When the template of the instruction is parsed again update(element,binding){
element.value = binding.value } } } }) </script>
</html>
边栏推荐
- Solution to the error of running NPM run eject
- 毕业两年月薪36k,说难也不难吧
- 第 3 篇:绘制三角形
- 『C语言』系统日期&时间
- 解决 These dependencies were not found: * core-js/modules/es6.array.fill in xxx 之类的问题
- 报错“Computation failed in `stat_summary_hex()`”
- 运行npm run eject报错解决方法
- L1-019 谁先倒 (15 分)
- Duilib display memory picture
- 使用 kubeconfig 文件组织集群访问
猜你喜欢

Review of postgraduate English final exam

On the H5 page, the Apple phone blocks the content when using fixed to locate the bottom of the tabbar

语料库数据处理个案实例(句子检索相关个案)

保留一位小数和保留两位小数

基于Distiller的模型压缩工具简介

宝塔面板安装php7.2安装phalcon3.3.2

Chapitre 2: dessiner une fenêtre

一文理解同步FIFO

Error:Kotlin: Module was compiled with an incompatible version of Kotlin. The binary version of its
![[nilm] non intrusive load decomposition module nilmtk installation tutorial](/img/d0/bc5ea1cbca9ee96a2fe168484ffec4.png)
[nilm] non intrusive load decomposition module nilmtk installation tutorial
随机推荐
[test development] first knowledge of software testing
Examples of corpus data processing cases (reading multiple text files, reading multiple files specified under a folder, decoding errors, reading multiple subfolder text, batch renaming of multiple fil
【资料上新】迅为基于3568开发板的NPU开发资料全面升级
auto使用示例
3-list introduction
Resolution error: LNK2019 unresolved external symbol
Gossip: what happened to 3aC?
Free ICP domain name filing interface
Notes on the use of date and time base
力扣(LeetCode)174. 地下城游戏(2022.06.23)
Selenium IDE的安装以及使用
Vulnhub靶机:BOREDHACKERBLOG: SOCIAL NETWORK
ImportError: cannot import name ‘process_ pdf‘ from ‘pdfminer. Pdfinterp 'error completely resolved
[C language] system date & time
LeetCode练习——跳跃游戏、组合求和
Backup and restore SQL Server Databases locally
What kind of experience is it when the Institute earns 20000 yuan a month!
鸿蒙os开发三
Take my brother to make a real-time Leaderboard
常见的数组封装